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

BUX-480: Record Transaction #548

Merged
merged 17 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions action_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,37 @@ func Test_RevertTransaction(t *testing.T) {
})
}

func Test_RecordTransaction(t *testing.T) {
//var secondTransaction *Transaction
t.Run("record transaction", func(t *testing.T) {
arkadiuszos4chain marked this conversation as resolved.
Show resolved Hide resolved
ctx, client, _ := initSimpleTestCase(t)
// given
draftTransaction := newDraftTransaction(
testXPub, &TransactionConfig{
Outputs: []*TransactionOutput{{
To: "1A1PjKqjWMNBzTVdcBru27EV1PHcXWc63W",
Satoshis: 1000,
}},
ChangeNumberOfDestinations: 1,
Sync: &SyncConfig{
Broadcast: true,
BroadcastInstant: false,
PaymailP2P: false,
SyncOnChain: false,
},
},
append(client.DefaultModelOptions(), New())...,
arkadiuszos4chain marked this conversation as resolved.
Show resolved Hide resolved
)

// when
_, err := client.RecordTransaction(ctx, testXPub, "test", draftTransaction.ID, client.DefaultModelOptions()...)

//then
require.Error(t, err)
})

}

func initRevertTransactionData(t *testing.T) (context.Context, ClientInterface, *Transaction, *bip32.ExtendedKey, func()) {
// this creates an xpub, destination and utxo
ctx, client, deferMe := initSimpleTestCase(t)
Expand Down
7 changes: 7 additions & 0 deletions paymail_service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,18 @@ func (p *PaymailDefaultServiceProvider) RecordTransaction(ctx context.Context,
metadata[p2pMetadataField] = p2pTx.MetaData
metadata[ReferenceIDField] = p2pTx.Reference

//var rts recordIncomingTxStrategy
arkadiuszos4chain marked this conversation as resolved.
Show resolved Hide resolved
//if err := rts.Validate(); err != nil {
// return nil, err
//}
// Record the transaction
rts, err := getIncomingTxRecordStrategy(ctx, p.client, p2pTx.Hex)
if err != nil {
return nil, err
}
if err := rts.Validate(); err != nil {
return nil, err
}

rts.ForceBroadcast(true)

Expand Down
4 changes: 4 additions & 0 deletions record_tx_strategy_external_incoming_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (strategy *externalIncomingTx) Validate() error {
return ErrMissingFieldHex
}

if _, err := bt.NewTxFromString(strategy.Hex); err != nil {
Nazarii-4chain marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("invalid hex: %w", err)
}

return nil // is valid
}

Expand Down
5 changes: 5 additions & 0 deletions record_tx_strategy_internal_incoming_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"

"github.com/libsv/go-bt/v2"
"github.com/rs/zerolog"
)

Expand Down Expand Up @@ -52,6 +53,10 @@ func (strategy *internalIncomingTx) Validate() error {
return errors.New("tx cannot be nil")
}

if _, err := bt.NewTxFromString(strategy.Tx.Hex); err != nil {
return fmt.Errorf("invalid hex: %w", err)
}

return nil // is valid
}

Expand Down
4 changes: 4 additions & 0 deletions record_tx_strategy_outgoing_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (strategy *outgoingTx) Validate() error {
return ErrMissingFieldHex
}

if _, err := bt.NewTxFromString(strategy.Hex); err != nil {
return fmt.Errorf("invalid hex: %w", err)
}

if strategy.RelatedDraftID == "" {
return errors.New("empty RelatedDraftID")
}
Expand Down
Loading