mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 13:38:35 +00:00
rpc: introduce proper type for sendrawtransaction, drop useless types
sendrawtransaction just returns a bool, sendtoaddress returns a proper transaction and that should be the same as the one we have in TransactionOutputRaw.
This commit is contained in:
parent
465476201c
commit
bba8ac15ff
2 changed files with 17 additions and 50 deletions
|
@ -112,10 +112,10 @@ func (c *Client) Invoke(script string, params []smartcontract.Parameter) (*respo
|
||||||
// The given hex string needs to be signed with a keypair.
|
// The given hex string needs to be signed with a keypair.
|
||||||
// When the result of the response object is true, the TX has successfully
|
// When the result of the response object is true, the TX has successfully
|
||||||
// been broadcasted to the network.
|
// been broadcasted to the network.
|
||||||
func (c *Client) sendRawTransaction(rawTX *transaction.Transaction) (*response.Raw, error) {
|
func (c *Client) sendRawTransaction(rawTX *transaction.Transaction) (*response.SendRawTx, error) {
|
||||||
var (
|
var (
|
||||||
params = request.NewRawParams(hex.EncodeToString(rawTX.Bytes()))
|
params = request.NewRawParams(hex.EncodeToString(rawTX.Bytes()))
|
||||||
resp = &response.Raw{}
|
resp = &response.SendRawTx{}
|
||||||
)
|
)
|
||||||
if err := c.performRequest("sendrawtransaction", params, resp); err != nil {
|
if err := c.performRequest("sendrawtransaction", params, resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -126,7 +126,7 @@ func (c *Client) sendRawTransaction(rawTX *transaction.Transaction) (*response.R
|
||||||
// SendToAddress sends an amount of specific asset to a given address.
|
// SendToAddress sends an amount of specific asset to a given address.
|
||||||
// This call requires open wallet. (`wif` key in client struct.)
|
// This call requires open wallet. (`wif` key in client struct.)
|
||||||
// If response.Result is `true` then transaction was formed correctly and was written in blockchain.
|
// If response.Result is `true` then transaction was formed correctly and was written in blockchain.
|
||||||
func (c *Client) SendToAddress(asset util.Uint256, address string, amount util.Fixed8) (*response.SendToAddress, error) {
|
func (c *Client) SendToAddress(asset util.Uint256, address string, amount util.Fixed8) (util.Uint256, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
rawTx *transaction.Transaction
|
rawTx *transaction.Transaction
|
||||||
|
@ -137,23 +137,21 @@ func (c *Client) SendToAddress(asset util.Uint256, address string, amount util.F
|
||||||
WIF: c.WIF(),
|
WIF: c.WIF(),
|
||||||
Balancer: c.Balancer(),
|
Balancer: c.Balancer(),
|
||||||
}
|
}
|
||||||
respRaw *response.Raw
|
respRaw *response.SendRawTx
|
||||||
resp = &response.SendToAddress{}
|
resp = util.Uint256{}
|
||||||
)
|
)
|
||||||
|
|
||||||
if rawTx, err = request.CreateRawContractTransaction(txParams); err != nil {
|
if rawTx, err = request.CreateRawContractTransaction(txParams); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to create raw transaction for `sendtoaddress`")
|
return resp, errors.Wrap(err, "failed to create raw transaction for `sendtoaddress`")
|
||||||
}
|
}
|
||||||
if respRaw, err = c.sendRawTransaction(rawTx); err != nil {
|
if respRaw, err = c.sendRawTransaction(rawTx); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to send raw transaction")
|
return resp, errors.Wrap(err, "failed to send raw transaction")
|
||||||
}
|
}
|
||||||
resp.Error = respRaw.Error
|
if respRaw.Result {
|
||||||
resp.ID = respRaw.ID
|
return rawTx.Hash(), nil
|
||||||
resp.JSONRPC = respRaw.JSONRPC
|
} else {
|
||||||
resp.Result = &response.Tx{
|
return resp, errors.New("failed to send raw transaction")
|
||||||
TxID: rawTx.Hash().StringLE(),
|
|
||||||
}
|
}
|
||||||
return resp, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignAndPushInvocationTx signs and pushes given script as an invocation
|
// SignAndPushInvocationTx signs and pushes given script as an invocation
|
||||||
|
|
|
@ -3,7 +3,6 @@ package response
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
|
||||||
"github.com/CityOfZion/neo-go/pkg/rpc/request"
|
"github.com/CityOfZion/neo-go/pkg/rpc/request"
|
||||||
"github.com/CityOfZion/neo-go/pkg/rpc/response/result"
|
"github.com/CityOfZion/neo-go/pkg/rpc/response/result"
|
||||||
"github.com/CityOfZion/neo-go/pkg/vm"
|
"github.com/CityOfZion/neo-go/pkg/vm"
|
||||||
|
@ -59,7 +58,7 @@ type Raw struct {
|
||||||
// SendToAddress stores response for the sendtoaddress call.
|
// SendToAddress stores response for the sendtoaddress call.
|
||||||
type SendToAddress struct {
|
type SendToAddress struct {
|
||||||
HeaderAndError
|
HeaderAndError
|
||||||
Result *Tx
|
Result *result.TransactionOutputRaw
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTxOut represents result of `gettxout` RPC call.
|
// GetTxOut represents result of `gettxout` RPC call.
|
||||||
|
@ -71,41 +70,11 @@ type GetTxOut struct {
|
||||||
// GetRawTx represents verbose output of `getrawtransaction` RPC call.
|
// GetRawTx represents verbose output of `getrawtransaction` RPC call.
|
||||||
type GetRawTx struct {
|
type GetRawTx struct {
|
||||||
HeaderAndError
|
HeaderAndError
|
||||||
Result *RawTx `json:"result"`
|
Result *result.TransactionOutputRaw `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RawTx stores transaction with blockchain metadata to be sent as a response.
|
// SendRawTx represents a `sendrawtransaction` RPC call response.
|
||||||
type RawTx struct {
|
type SendRawTx struct {
|
||||||
Tx
|
HeaderAndError
|
||||||
BlockHash string `json:"blockhash"`
|
Result bool `json:"result"`
|
||||||
Confirmations uint `json:"confirmations"`
|
|
||||||
BlockTime uint `json:"blocktime"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tx stores transaction to be sent as a response.
|
|
||||||
type Tx struct {
|
|
||||||
TxID string `json:"txid"`
|
|
||||||
Size int `json:"size"`
|
|
||||||
Type string `json:"type"` // todo: convert to TransactionType
|
|
||||||
Version int `json:"version"`
|
|
||||||
Attributes []transaction.Attribute `json:"attributes"`
|
|
||||||
Vins []Vin `json:"vin"`
|
|
||||||
Vouts []Vout `json:"vout"`
|
|
||||||
SysFee int `json:"sys_fee"`
|
|
||||||
NetFee int `json:"net_fee"`
|
|
||||||
Scripts []transaction.Witness `json:"scripts"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vin represents JSON-serializable tx input.
|
|
||||||
type Vin struct {
|
|
||||||
TxID string `json:"txid"`
|
|
||||||
Vout int `json:"vout"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vout represents JSON-serializable tx output.
|
|
||||||
type Vout struct {
|
|
||||||
N int `json:"n"`
|
|
||||||
Asset string `json:"asset"`
|
|
||||||
Value int `json:"value"`
|
|
||||||
Address string `json:"address"`
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue