Skip to content

Commit

Permalink
refactor: introducing Broadcaster{} struct, which is like Context{} b…
Browse files Browse the repository at this point in the history
…ut only handles broadcasting
  • Loading branch information
randomshinichi committed Jan 21, 2020
1 parent 245f5e3 commit 0f3625c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,30 @@ func getNetworkID(n naet.GetStatuser) (networkID string, err error) {
networkID = *status.NetworkID
return
}

type broadcasterNodeCapabilities interface {
naet.GetStatuser
broadcastWaitTransactionNodeCapabilities
}
type Broadcaster struct {
signingAcc *account.Account
networkID string
node broadcastWaitTransactionNodeCapabilities
}

func NewBroadcaster(signingAccount *account.Account, node broadcasterNodeCapabilities) (b *Broadcaster, err error) {
networkID, err := getNetworkID(node)
if err != nil {
return
}

return &Broadcaster{
signingAcc: signingAccount,
node: node,
networkID: networkID,
}, nil
}

func (b *Broadcaster) SignBroadcastWait(tx transactions.Transaction, blocks uint64) (signedTxStr, hash, signature string, blockHeight uint64, blockHash string, err error) {
return SignBroadcastWaitTransaction(tx, b.signingAcc, b.node, b.networkID, blocks)
}

0 comments on commit 0f3625c

Please sign in to comment.