Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
fix: pull request changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wregulski committed Dec 8, 2023
1 parent 1813b55 commit 26293d4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
13 changes: 4 additions & 9 deletions beef_bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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())
Expand All @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions beef_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ 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)
}

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)
}
Expand All @@ -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,
}

Expand Down
1 change: 0 additions & 1 deletion model_draft_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26293d4

Please sign in to comment.