Skip to content

Commit f8436b5

Browse files
authored
Merge pull request #46 from bitcoin-sv/update/docs
documentation / example updates
2 parents 7876bc5 + 5beaf69 commit f8436b5

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

docs/examples/GO_BT.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Convert from libsv/go-bt transaction
2+
3+
For users of libsv/go-bt library, this function illustrates the differences between the two transaction structures and converts from one to the other.
4+
5+
```go
6+
func GoBt2GoSDKTransaction(tx *bt.Tx) *transaction.Transaction {
7+
sdkTx := &transaction.Transaction{
8+
Version: tx.Version,
9+
LockTime: tx.LockTime,
10+
}
11+
12+
sdkTx.Inputs = make([]*transaction.TransactionInput, len(tx.Inputs))
13+
for i, in := range tx.Inputs {
14+
sdkTx.Inputs[i] = &transaction.TransactionInput{
15+
SourceTXID: bt.ReverseBytes(in.PreviousTxID()),
16+
SourceTxOutIndex: in.PreviousTxOutIndex,
17+
UnlockingScript: (*script.Script)(in.UnlockingScript),
18+
SequenceNumber: in.SequenceNumber,
19+
}
20+
}
21+
22+
sdkTx.Outputs = make([]*transaction.TransactionOutput, len(tx.Outputs))
23+
for i, out := range tx.Outputs {
24+
sdkTx.Outputs[i] = &transaction.TransactionOutput{
25+
Satoshis: out.Satoshis,
26+
LockingScript: (*script.Script)(out.LockingScript),
27+
}
28+
}
29+
30+
return sdkTx
31+
}
32+
```

docs/examples/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# Examples
22

33
Here, you will find a number of common usage examples for the go-sdk.
4+
5+
## Additional Example Documents
6+
- [Converting Transactions from go-bt][GO_BT.md]

0 commit comments

Comments
 (0)