Skip to content

Commit

Permalink
feat: add ExecuteAll to consensus submit and transaction list. Also…
Browse files Browse the repository at this point in the history
… change return type of Execute back to a singel txID
  • Loading branch information
janaakhterov committed Jul 16, 2020
1 parent f9ad310 commit 13a81e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 10 additions & 2 deletions consensus_message_submit_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,23 @@ func (builder ConsensusMessageSubmitTransaction) SetChunkInfo(transactionID Tran
return builder
}

func (builder ConsensusMessageSubmitTransaction) Execute(client *Client) ([]TransactionID, error) {
func (builder ConsensusMessageSubmitTransaction) Execute(client *Client) (TransactionID, error) {
txs, err := builder.Build(client)
if err != nil {
return nil, err
return TransactionID{}, err
}

return txs.Execute(client)
}

func (builder ConsensusMessageSubmitTransaction) ExecuteAll(client *Client) ([]TransactionID, error) {
txs, err := builder.Build(client)
if err != nil {
return nil, err
}

return txs.ExecuteAll(client)
}
func (builder ConsensusMessageSubmitTransaction) Build(client *Client) (TransactionList, error) {
// If chunk info is set then we aren't going to chunk the message
// Set all the required fields and return a list of 1
Expand Down
18 changes: 17 additions & 1 deletion transaction_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (list TransactionList) SignWith(publicKey Ed25519PublicKey, signer Transact
return list
}

func (list TransactionList) Execute(client *Client) ([]TransactionID, error) {
func (list TransactionList) ExecuteAll(client *Client) ([]TransactionID, error) {
ids := make([]TransactionID, len(list.List))
for i, tx := range list.List {
id, err := tx.Execute(client)
Expand All @@ -36,3 +36,19 @@ func (list TransactionList) Execute(client *Client) ([]TransactionID, error) {

return ids, nil
}

func (list TransactionList) Execute(client *Client) (TransactionID, error) {
var lastID TransactionID
for i, tx := range list.List {
id, err := tx.Execute(client)
if err != nil {
return TransactionID{}, err
}

if i == len(list.List) - 1 {
lastID = id
}
}

return lastID, nil
}

0 comments on commit 13a81e6

Please sign in to comment.