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 @@ -269,6 +269,20 @@ func (t *Transaction) HashHex(network string) (string, error) {
return hashHex(t.envelope, network)
}

// Generates TranscationParam from a Transcation, Pass your own increment sequence flag.
func (t *Transaction) ConvertToTransactionParam(incrementSeqFlag bool) *TransactionParams {
MishraShivendra marked this conversation as resolved.
Show resolved Hide resolved
MishraShivendra marked this conversation as resolved.
Show resolved Hide resolved
srcAccount := t.SourceAccount()
tp := TransactionParams{
Memo: t.Memo(),
Operations: t.Operations(),
Timebounds: t.Timebounds(),
BaseFee: t.BaseFee(),
SourceAccount: &srcAccount,
IncrementSequenceNum: incrementSeqFlag,
MishraShivendra marked this conversation as resolved.
Show resolved Hide resolved
}
return &tp
}

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

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

tb := NewTimeout(300)
transParam := TransactionParams{
SourceAccount: &SimpleAccount{AccountID: kp0.Address(), Sequence: 1},
Operations: []Operation{&BumpSequence{BumpTo: 0}},
BaseFee: MinBaseFee,
Timebounds: tb,
}
tx, err := NewTransaction(transParam)
assert.NoError(t, err)
ConvertedTrans := tx.ConvertToTransactionParam(transParam.IncrementSequenceNum)
assert.Equal(t, *ConvertedTrans, transParam)
}