mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-24 09:25:21 +00:00
rpc: fix adding extra network fee to tx
This commit is contained in:
parent
3c551788c9
commit
966ad8a0b1
2 changed files with 13 additions and 19 deletions
|
@ -115,17 +115,6 @@ func (c *Client) CreateNEP5TransferTx(acc *wallet.Account, to util.Uint160, toke
|
||||||
emit.Opcode(w.BinWriter, opcode.ASSERT)
|
emit.Opcode(w.BinWriter, opcode.ASSERT)
|
||||||
|
|
||||||
script := w.Bytes()
|
script := w.Bytes()
|
||||||
tx := transaction.New(c.opts.Network, script, gas)
|
|
||||||
tx.Sender = from
|
|
||||||
tx.Cosigners = []transaction.Cosigner{
|
|
||||||
{
|
|
||||||
Account: from,
|
|
||||||
Scopes: transaction.CalledByEntry,
|
|
||||||
AllowedContracts: nil,
|
|
||||||
AllowedGroups: nil,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := c.InvokeScript(script, []transaction.Cosigner{
|
result, err := c.InvokeScript(script, []transaction.Cosigner{
|
||||||
{
|
{
|
||||||
Account: from,
|
Account: from,
|
||||||
|
@ -135,16 +124,20 @@ func (c *Client) CreateNEP5TransferTx(acc *wallet.Account, to util.Uint160, toke
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't add system fee to transaction: %v", err)
|
return nil, fmt.Errorf("can't add system fee to transaction: %v", err)
|
||||||
}
|
}
|
||||||
if result.GasConsumed > 0 {
|
tx := transaction.New(c.opts.Network, script, result.GasConsumed)
|
||||||
tx.SystemFee = result.GasConsumed
|
tx.Sender = from
|
||||||
|
tx.Cosigners = []transaction.Cosigner{
|
||||||
|
{
|
||||||
|
Account: from,
|
||||||
|
Scopes: transaction.CalledByEntry,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.ValidUntilBlock, err = c.CalculateValidUntilBlock()
|
tx.ValidUntilBlock, err = c.CalculateValidUntilBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't calculate validUntilBlock: %v", err)
|
return nil, fmt.Errorf("can't calculate validUntilBlock: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.AddNetworkFee(tx, acc)
|
err = c.AddNetworkFee(tx, gas, acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't add network fee to transaction: %v", err)
|
return nil, fmt.Errorf("can't add network fee to transaction: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -449,7 +449,7 @@ func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sys
|
||||||
}
|
}
|
||||||
tx.Sender = addr
|
tx.Sender = addr
|
||||||
|
|
||||||
err = c.AddNetworkFee(tx, acc)
|
err = c.AddNetworkFee(tx, int64(netfee), acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return txHash, errors.Wrapf(err, "failed to add network fee")
|
return txHash, errors.Wrapf(err, "failed to add network fee")
|
||||||
}
|
}
|
||||||
|
@ -512,8 +512,9 @@ func (c *Client) CalculateValidUntilBlock() (uint32, error) {
|
||||||
return blockCount + validatorsCount, nil
|
return blockCount + validatorsCount, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddNetworkFee adds network fee for each witness script to transaction.
|
// AddNetworkFee adds network fee for each witness script and optional extra
|
||||||
func (c *Client) AddNetworkFee(tx *transaction.Transaction, acc *wallet.Account) error {
|
// network fee to transaction.
|
||||||
|
func (c *Client) AddNetworkFee(tx *transaction.Transaction, extraFee int64, acc *wallet.Account) error {
|
||||||
size := io.GetVarSize(tx)
|
size := io.GetVarSize(tx)
|
||||||
if acc.Contract != nil {
|
if acc.Contract != nil {
|
||||||
netFee, sizeDelta := core.CalculateNetworkFee(acc.Contract.Script)
|
netFee, sizeDelta := core.CalculateNetworkFee(acc.Contract.Script)
|
||||||
|
@ -540,6 +541,6 @@ func (c *Client) AddNetworkFee(tx *transaction.Transaction, acc *wallet.Account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tx.NetworkFee += int64(size) * fee
|
tx.NetworkFee += int64(size)*fee + extraFee
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue