Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txnbuild: add ToTransactionParams to Transaction #4334

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
14 changes: 14 additions & 0 deletions txnbuild/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,20 @@ func (t *Transaction) HashHex(network string) (string, error) {
return hashHex(t.envelope, network)
}

// Generates TransactionParams from a Transaction. ToTransactionParams() sets
// IncrementSequenceNum field to default in returned TransactionParams.
func (t *Transaction) ToTransactionParams() TransactionParams {
srcAccount := t.SourceAccount()
tp := TransactionParams{
Memo: t.Memo(),
Operations: t.Operations(),
BaseFee: t.BaseFee(),
SourceAccount: &srcAccount,
Preconditions: t.preconditions,
}
return tp
}

func (t *Transaction) clone(signatures []xdr.DecoratedSignature) *Transaction {
newTx := new(Transaction)
*newTx = *t
Expand Down
21 changes: 21 additions & 0 deletions txnbuild/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5089,3 +5089,24 @@ func TestGenericTransaction_HashHex(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, expected, hashHex)
}

func TestTransToTransParamConvert(t *testing.T) {
kp0 := newKeypair0()

transParam := TransactionParams{
SourceAccount: &SimpleAccount{AccountID: kp0.Address(), Sequence: 1},
Operations: []Operation{&BumpSequence{BumpTo: 0}},
BaseFee: MinBaseFee,
Preconditions: Preconditions{
TimeBounds: NewTimeout(300),
LedgerBounds: &LedgerBounds{0, 1},
MinSequenceNumber: nil,
MinSequenceNumberAge: 10,
MinSequenceNumberLedgerGap: 2,
},
}
tx, err := NewTransaction(transParam)
assert.NoError(t, err)
ConvertedTransParam := tx.ToTransactionParams()
assert.Equal(t, ConvertedTransParam, transParam)
}