2018-03-05 08:53:09 +00:00
|
|
|
package rpc
|
|
|
|
|
2019-02-19 11:47:25 +00:00
|
|
|
import (
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
2019-11-19 17:15:32 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/rpc/wrappers"
|
2019-02-19 11:47:25 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/vm"
|
|
|
|
)
|
2019-01-22 12:14:40 +00:00
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// InvokeScriptResponse stores response for the invoke script call.
|
2018-03-05 08:53:09 +00:00
|
|
|
type InvokeScriptResponse struct {
|
|
|
|
responseHeader
|
2018-05-13 18:32:45 +00:00
|
|
|
Error *Error `json:"error,omitempty"`
|
|
|
|
Result *InvokeResult `json:"result,omitempty"`
|
2018-03-05 08:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// InvokeResult represents the outcome of a script that is
|
|
|
|
// executed by the NEO VM.
|
|
|
|
type InvokeResult struct {
|
2019-02-19 11:47:25 +00:00
|
|
|
State vm.State `json:"state"`
|
|
|
|
GasConsumed string `json:"gas_consumed"`
|
|
|
|
Script string `json:"script"`
|
2019-01-25 11:20:35 +00:00
|
|
|
Stack []StackParam
|
2018-03-05 08:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AccountStateResponse holds the getaccountstate response.
|
|
|
|
type AccountStateResponse struct {
|
|
|
|
responseHeader
|
|
|
|
Result *Account `json:"result"`
|
|
|
|
}
|
|
|
|
|
2019-11-19 17:15:32 +00:00
|
|
|
// UnspentResponse represents server response to the `getunspents` command.
|
|
|
|
type UnspentResponse struct {
|
|
|
|
responseHeader
|
|
|
|
Error *Error `json:"error,omitempty"`
|
|
|
|
Result *wrappers.Unspents `json:"result,omitempty"`
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:01:10 +00:00
|
|
|
// Account represents details about a NEO account.
|
2018-03-05 08:53:09 +00:00
|
|
|
type Account struct {
|
|
|
|
Version int `json:"version"`
|
|
|
|
ScriptHash string `json:"script_hash"`
|
|
|
|
Frozen bool
|
|
|
|
// TODO: need to check this field out.
|
|
|
|
Votes []interface{}
|
|
|
|
Balances []*Balance
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:01:10 +00:00
|
|
|
// Balance represents details about a NEO account balance.
|
2018-03-05 08:53:09 +00:00
|
|
|
type Balance struct {
|
|
|
|
Asset string `json:"asset"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type params struct {
|
|
|
|
values []interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newParams(vals ...interface{}) params {
|
|
|
|
p := params{}
|
|
|
|
p.values = make([]interface{}, len(vals))
|
|
|
|
for i := 0; i < len(p.values); i++ {
|
|
|
|
p.values[i] = vals[i]
|
|
|
|
}
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
type request struct {
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
|
|
|
Method string `json:"method"`
|
|
|
|
Params []interface{} `json:"params"`
|
|
|
|
ID int `json:"id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type responseHeader struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
JSONRPC string `json:"jsonrpc"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type response struct {
|
|
|
|
responseHeader
|
2018-05-13 18:32:45 +00:00
|
|
|
Error *Error `json:"error"`
|
2018-03-05 08:53:09 +00:00
|
|
|
Result interface{} `json:"result"`
|
|
|
|
}
|
2019-01-22 12:14:40 +00:00
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// SendToAddressResponse stores response for the sendtoaddress call.
|
2019-01-22 12:14:40 +00:00
|
|
|
type SendToAddressResponse struct {
|
|
|
|
responseHeader
|
|
|
|
Error *Error `json:"error"`
|
|
|
|
Result *TxResponse
|
|
|
|
}
|
|
|
|
|
2019-10-22 14:56:03 +00:00
|
|
|
// GetRawTxResponse represents verbose output of `getrawtransaction` RPC call.
|
2019-01-22 12:14:40 +00:00
|
|
|
type GetRawTxResponse struct {
|
|
|
|
responseHeader
|
|
|
|
Error *Error `json:"error"`
|
2019-01-25 11:20:35 +00:00
|
|
|
Result *RawTxResponse `json:"result"`
|
2019-01-22 12:14:40 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 12:02:03 +00:00
|
|
|
// GetTxOutResponse represents result of `gettxout` RPC call.
|
|
|
|
type GetTxOutResponse struct {
|
|
|
|
responseHeader
|
|
|
|
Error *Error
|
|
|
|
Result *wrappers.TransactionOutput
|
|
|
|
}
|
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// RawTxResponse stores transaction with blockchain metadata to be sent as a response.
|
2019-01-22 12:14:40 +00:00
|
|
|
type RawTxResponse struct {
|
|
|
|
TxResponse
|
2019-01-25 11:20:35 +00:00
|
|
|
BlockHash string `json:"blockhash"`
|
|
|
|
Confirmations uint `json:"confirmations"`
|
|
|
|
BlockTime uint `json:"blocktime"`
|
2019-01-22 12:14:40 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// TxResponse stores transaction to be sent as a response.
|
2019-01-22 12:14:40 +00:00
|
|
|
type TxResponse struct {
|
2019-01-25 11:20:35 +00:00
|
|
|
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"`
|
2019-01-22 12:14:40 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// Vin represents JSON-serializable tx input.
|
2019-01-22 12:14:40 +00:00
|
|
|
type Vin struct {
|
2019-09-03 15:11:13 +00:00
|
|
|
TxID string `json:"txid"`
|
2019-01-25 11:20:35 +00:00
|
|
|
Vout int `json:"vout"`
|
2019-01-22 12:14:40 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// Vout represents JSON-serializable tx output.
|
2019-01-22 12:14:40 +00:00
|
|
|
type Vout struct {
|
2019-01-25 11:20:35 +00:00
|
|
|
N int `json:"n"`
|
|
|
|
Asset string `json:"asset"`
|
|
|
|
Value int `json:"value"`
|
|
|
|
Address string `json:"address"`
|
2019-01-22 12:14:40 +00:00
|
|
|
}
|