From 26293d418007869e682fb3cb963cf6796320ea23 Mon Sep 17 00:00:00 2001 From: wregulski Date: Thu, 23 Nov 2023 14:03:45 +0100 Subject: [PATCH] fix: pull request changes --- beef_bump.go | 13 ++++--------- beef_tx.go | 16 ++++++++-------- model_draft_transactions.go | 1 - 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/beef_bump.go b/beef_bump.go index 370945c3..4222a8d2 100644 --- a/beef_bump.go +++ b/beef_bump.go @@ -56,7 +56,7 @@ func validateBumps(bumps BUMPs) error { return nil } -func prepareBUMPFactors(ctx context.Context, tx *Transaction, store TransactionGetter) ([]*bt.Tx, []*Transaction, error) { +func prepareBEEFFactors(ctx context.Context, tx *Transaction, store TransactionGetter) ([]*bt.Tx, []*Transaction, error) { btTxsNeededForBUMP, txsNeededForBUMP, err := initializeRequiredTxsCollection(tx) if err != nil { return nil, nil, err @@ -87,7 +87,7 @@ func prepareBUMPFactors(ctx context.Context, tx *Transaction, store TransactionG btTxsNeededForBUMP = append(btTxsNeededForBUMP, inputBtTx) if inputTx.BUMP.BlockHeight == 0 && len(inputTx.BUMP.Path) == 0 { - parentBtTransactions, parentTransactions, err := checkParentTransactions(ctx, store, inputTx) + parentBtTransactions, parentTransactions, err := checkParentTransactions(ctx, store, inputBtTx) if err != nil { return nil, nil, err } @@ -100,12 +100,7 @@ func prepareBUMPFactors(ctx context.Context, tx *Transaction, store TransactionG return btTxsNeededForBUMP, txsNeededForBUMP, nil } -func checkParentTransactions(ctx context.Context, store TransactionGetter, inputTx *Transaction) ([]*bt.Tx, []*Transaction, error) { - btTx, err := bt.NewTxFromString(inputTx.Hex) - if err != nil { - return nil, nil, fmt.Errorf("cannot convert to bt.Tx from hex (tx.ID: %s). Reason: %w", inputTx.ID, err) - } - +func checkParentTransactions(ctx context.Context, store TransactionGetter, btTx *bt.Tx) ([]*bt.Tx, []*Transaction, error) { var parentTxIDs []string for _, txIn := range btTx.Inputs { parentTxIDs = append(parentTxIDs, txIn.PreviousTxIDStr()) @@ -132,7 +127,7 @@ func checkParentTransactions(ctx context.Context, store TransactionGetter, input validBtTxs = append(validBtTxs, parentBtTx) if parentTx.BUMP.BlockHeight == 0 && len(parentTx.BUMP.Path) == 0 { - parentValidBtTxs, parentValidTxs, err := checkParentTransactions(ctx, store, parentTx) + parentValidBtTxs, parentValidTxs, err := checkParentTransactions(ctx, store, parentBtTx) if err != nil { return nil, nil, err } diff --git a/beef_tx.go b/beef_tx.go index 425c31ab..b8b60e69 100644 --- a/beef_tx.go +++ b/beef_tx.go @@ -22,14 +22,14 @@ func ToBeef(ctx context.Context, tx *Transaction, store TransactionGetter) (stri return "", err } - bumpBtFactors, bumpFactors, err := prepareBUMPFactors(ctx, tx, store) + bumpBtFactors, bumpFactors, err := prepareBEEFFactors(ctx, tx, store) if err != nil { return "", fmt.Errorf("prepareBUMPFactors() error: %w", err) } - tx.draftTransaction.BUMPs, err = calculateMergedBUMP(bumpFactors) + bumps, err := calculateMergedBUMP(bumpFactors) sortedTxs := kahnTopologicalSortTransactions(bumpBtFactors) - beefHex, err := toBeefHex(ctx, tx, sortedTxs) + beefHex, err := toBeefHex(ctx, bumps, sortedTxs) if err != nil { return "", fmt.Errorf("ToBeef() error: %w", err) } @@ -37,8 +37,8 @@ func ToBeef(ctx context.Context, tx *Transaction, store TransactionGetter) (stri return beefHex, nil } -func toBeefHex(ctx context.Context, tx *Transaction, parentTxs []*bt.Tx) (string, error) { - beef, err := newBeefTx(ctx, 1, tx, parentTxs) +func toBeefHex(ctx context.Context, bumps BUMPs, parentTxs []*bt.Tx) (string, error) { + beef, err := newBeefTx(ctx, 1, bumps, parentTxs) if err != nil { return "", fmt.Errorf("ToBeefHex() error: %w", err) } @@ -51,18 +51,18 @@ func toBeefHex(ctx context.Context, tx *Transaction, parentTxs []*bt.Tx) (string return hex.EncodeToString(beefBytes), nil } -func newBeefTx(ctx context.Context, version uint32, tx *Transaction, parentTxs []*bt.Tx) (*beefTx, error) { +func newBeefTx(ctx context.Context, version uint32, bumps BUMPs, parentTxs []*bt.Tx) (*beefTx, error) { if version > maxBeefVer { return nil, fmt.Errorf("version above 0x%X", maxBeefVer) } - if err := validateBumps(tx.draftTransaction.BUMPs); err != nil { + if err := validateBumps(bumps); err != nil { return nil, err } beef := &beefTx{ version: version, - bumps: tx.draftTransaction.BUMPs, + bumps: bumps, transactions: parentTxs, } diff --git a/model_draft_transactions.go b/model_draft_transactions.go index 1b644766..6d22c734 100644 --- a/model_draft_transactions.go +++ b/model_draft_transactions.go @@ -38,7 +38,6 @@ type DraftTransaction struct { Configuration TransactionConfig `json:"configuration" toml:"configuration" yaml:"configuration" gorm:"<-;type:text;comment:This is the configuration struct in JSON" bson:"configuration"` Status DraftStatus `json:"status" toml:"status" yaml:"status" gorm:"<-;type:varchar(10);index;comment:This is the status of the draft" bson:"status"` FinalTxID string `json:"final_tx_id,omitempty" toml:"final_tx_id" yaml:"final_tx_id" gorm:"<-;type:char(64);index;comment:This is the final tx ID" bson:"final_tx_id,omitempty"` - BUMPs BUMPs `json:"bumps,omitempty" toml:"bumps" yaml:"bumps" gorm:"<-;type:text;comment:Slice of BUMPs (BSV Unified Merkle Paths)" bson:"bumps,omitempty"` } // newDraftTransaction will start a new draft tx