This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
generated from mrz1836/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(BUX-598): broadcast in EF if possible
- Loading branch information
1 parent
dde5783
commit 7b28325
Showing
16 changed files
with
272 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package bux | ||
|
||
import ( | ||
"context" | ||
"encoding/hex" | ||
|
||
"github.com/libsv/go-bt/v2" | ||
) | ||
|
||
func ToEfHex(ctx context.Context, tx *Transaction, store TransactionGetter) (efHex string, ok bool) { | ||
btTx := tx.parsedTx | ||
|
||
if btTx == nil { | ||
var err error | ||
btTx, err = bt.NewTxFromString(tx.Hex) | ||
if err != nil { | ||
return "", false | ||
} | ||
} | ||
|
||
needToHydrate := false | ||
for _, input := range btTx.Inputs { | ||
if input.PreviousTxScript == nil { | ||
needToHydrate = true | ||
break | ||
} | ||
} | ||
|
||
if needToHydrate { | ||
if ok := hydrate(ctx, btTx, store); !ok { | ||
return "", false | ||
} | ||
} | ||
|
||
return hex.EncodeToString(btTx.ExtendedBytes()), true | ||
} | ||
|
||
func hydrate(ctx context.Context, tx *bt.Tx, store TransactionGetter) (ok bool) { | ||
txToGet := make([]string, 0, len(tx.Inputs)) | ||
|
||
for _, input := range tx.Inputs { | ||
txToGet = append(txToGet, input.PreviousTxIDStr()) | ||
} | ||
|
||
parentTxs, err := store.GetTransactionsByIDs(ctx, txToGet) | ||
if err != nil { | ||
return false | ||
} | ||
if len(parentTxs) != len(tx.Inputs) { | ||
return false | ||
} | ||
|
||
for _, input := range tx.Inputs { | ||
prevTxId := input.PreviousTxIDStr() | ||
pTx := find(parentTxs, func(tx *Transaction) bool { return tx.ID == prevTxId }) | ||
|
||
pbtTx, err := bt.NewTxFromString((*pTx).Hex) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
o := pbtTx.Outputs[input.PreviousTxOutIndex] | ||
input.PreviousTxSatoshis = o.Satoshis | ||
input.PreviousTxScript = o.LockingScript | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.