From 1d6ba389c9ef1dad2b166ebfc160cea3e6c0b844 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 21 Apr 2021 13:44:37 +0300 Subject: [PATCH] rpc: split SignAndPushInvocationTx in two parts There are several places where constructed transaction need to be signed and sent. Thus, we definitely need a separate method for signing and sending constructed transaction to avoid code duplication. --- pkg/rpc/client/rpc.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index 97deedfc1..db88ff0df 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -535,13 +535,22 @@ func (c *Client) SubmitRawOracleResponse(ps request.RawParams) error { // invocation transaction and an error. If one of the cosigners accounts is // neither contract-based nor unlocked an error is returned. func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sysfee int64, netfee fixedn.Fixed8, cosigners []SignerAccount) (util.Uint256, error) { - var txHash util.Uint256 - var err error - tx, err := c.CreateTxFromScript(script, acc, sysfee, int64(netfee), cosigners) if err != nil { - return txHash, fmt.Errorf("failed to create tx: %w", err) + return util.Uint256{}, fmt.Errorf("failed to create tx: %w", err) } + return c.SignAndPushTx(tx, acc, cosigners) +} + +// SignAndPushTx signs given transaction using given wif and cosigners and pushes +// it to the chain. It returns a hash of the transaction and an error. If one of +// the cosigners accounts is neither contract-based nor unlocked an error is +// returned. +func (c *Client) SignAndPushTx(tx *transaction.Transaction, acc *wallet.Account, cosigners []SignerAccount) (util.Uint256, error) { + var ( + txHash util.Uint256 + err error + ) if err = acc.SignTx(c.GetNetwork(), tx); err != nil { return txHash, fmt.Errorf("failed to sign tx: %w", err) }