Skip to content

Commit

Permalink
refactor: Context.SignBroadcast as well as SignBroadcastWait
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Jan 21, 2020
1 parent 12c2047 commit 6260ed9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions aeternity/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,26 @@ func (c *Context) NodeInfo() (networkID string, version string, err error) {
return *s.NetworkID, *s.NodeVersion, err
}

// SignBroadcastWait signs, sends and waits for the transaction to be mined.
func (c *Context) SignBroadcastWait(tx transactions.Transaction, blocks uint64) (txReceipt *TxReceipt, err error) {
// SignBroadcast signs, sends and returns immediately, just like
// aeternity.SignBroadcast. The difference is that the account used to sign the
// transaction and broadcasting node and network ID don't have to be provided
// every time.
func (c *Context) SignBroadcast(tx transactions.Transaction, blocks uint64) (txReceipt *TxReceipt, err error) {
networkID, _, err := c.NodeInfo()
if err != nil {
return
}
txReceipt, err = SignBroadcast(tx, c.SigningAccount, c.txSender, networkID)
if err != nil {
return
}
return SignBroadcast(tx, c.SigningAccount, c.txSender, networkID)

}

// SignBroadcastWait is just like SignBroadcast but integrates
// aeternity.WaitSynchronous afterwards, to block until the transaction is
// mined.
func (c *Context) SignBroadcastWait(tx transactions.Transaction, blocks uint64) (txReceipt *TxReceipt, err error) {
txReceipt, err = c.SignBroadcast(tx, blocks)
err = WaitSynchronous(txReceipt, blocks, c.txSender)
return txReceipt, err
return
}

// SetCompiler changes the Context's compiler instance.
Expand Down

0 comments on commit 6260ed9

Please sign in to comment.