I'm trying to write a function that will take an encoded string, send a request to the jsonrpc service, then I need to choose a boring data (ask:assets:interface) and create a new variables
How can I create structure for object:
{
"ask": {
"amount": 0,
"assets": [
{
"assetref": "74-266-27408",
"name": "USD",
"qty": 5000
}
]
},
"cancomplete": true,
"candisable": true,
"complete": false,
"offer": {
"amount": 0,
"assets": [
{
"assetref": "73-266-61482",
"name": "BTC",
"qty": 1
}
]
},
"requiredfee": 0
}
And make a function wich decode hex string:
type Order struct {
Ask []Ask `json:"ask"`
Cancomplete bool `json:"cancomplete"`
Candisable bool `json:"candisable"`
Complete bool `json:"complete"`
Offer []Offer `json:"offer"`
Requiredfee int `json:"requiredfee"`
}
func DecodeOrder(datahex string) (Order) {
order, _ := rpcClient.Call("decoderawexchange", datahex)
var d = make([]Order, 0, 100)
err := order.GetObject(&d)
if err != nil || d == nil {
panic(err)
}
return d
}
Issue resolved using generated structure:
type Order struct {
Ask struct {
Amount float64 `json:"amount"`
Assets []struct {
Assetref string `json:"assetref"`
Name string `json:"name"`
Qty float64 `json:"qty"`
} `json:"assets"`
} `json:"ask"`
Cancomplete bool `json:"cancomplete"`
Candisable bool `json:"candisable"`
Complete bool `json:"complete"`
Offer struct {
Amount float64 `json:"amount"`
Assets []struct {
Assetref string `json:"assetref"`
Name string `json:"name"`
Qty float64 `json:"qty"`
} `json:"assets"`
} `json:"offer"`
Requiredfee float64 `json:"requiredfee"`
}