forked from TrueCloudLab/neoneo-go
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.
|
||||
// When the result of the response object is true, the TX has successfully
|
||||
// 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 (
|
||||
params = request.NewRawParams(hex.EncodeToString(rawTX.Bytes()))
|
||||
resp = &response.Raw{}
|
||||
resp = &response.SendRawTx{}
|
||||
)
|
||||
if err := c.performRequest("sendrawtransaction", params, resp); err != nil {
|
||||
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.
|
||||
// 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.
|
||||
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 (
|
||||
err error
|
||||
rawTx *transaction.Transaction
|
||||
|
@ -137,23 +137,21 @@ func (c *Client) SendToAddress(asset util.Uint256, address string, amount util.F
|
|||
WIF: c.WIF(),
|
||||
Balancer: c.Balancer(),
|
||||
}
|
||||
respRaw *response.Raw
|
||||
resp = &response.SendToAddress{}
|
||||
respRaw *response.SendRawTx
|
||||
resp = util.Uint256{}
|
||||
)
|
||||
|
||||
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 {
|
||||
return nil, errors.Wrap(err, "failed to send raw transaction")
|
||||
return resp, errors.Wrap(err, "failed to send raw transaction")
|
||||
}
|
||||
resp.Error = respRaw.Error
|
||||
resp.ID = respRaw.ID
|
||||
resp.JSONRPC = respRaw.JSONRPC
|
||||
resp.Result = &response.Tx{
|
||||
TxID: rawTx.Hash().StringLE(),
|
||||
if respRaw.Result {
|
||||
return rawTx.Hash(), nil
|
||||
} else {
|
||||
return resp, errors.New("failed to send raw transaction")
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// SignAndPushInvocationTx signs and pushes given script as an invocation
|
||||
|
|
|
@ -3,7 +3,6 @@ package response
|
|||
import (
|
||||
"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/response/result"
|
||||
"github.com/CityOfZion/neo-go/pkg/vm"
|
||||
|
@ -59,7 +58,7 @@ type Raw struct {
|
|||
// SendToAddress stores response for the sendtoaddress call.
|
||||
type SendToAddress struct {
|
||||
HeaderAndError
|
||||
Result *Tx
|
||||
Result *result.TransactionOutputRaw
|
||||
}
|
||||
|
||||
// GetTxOut represents result of `gettxout` RPC call.
|
||||
|
@ -71,41 +70,11 @@ type GetTxOut struct {
|
|||
// GetRawTx represents verbose output of `getrawtransaction` RPC call.
|
||||
type GetRawTx struct {
|
||||
HeaderAndError
|
||||
Result *RawTx `json:"result"`
|
||||
Result *result.TransactionOutputRaw `json:"result"`
|
||||
}
|
||||
|
||||
// RawTx stores transaction with blockchain metadata to be sent as a response.
|
||||
type RawTx struct {
|
||||
Tx
|
||||
BlockHash string `json:"blockhash"`
|
||||
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"`
|
||||
// SendRawTx represents a `sendrawtransaction` RPC call response.
|
||||
type SendRawTx struct {
|
||||
HeaderAndError
|
||||
Result bool `json:"result"`
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue