-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
80 lines (72 loc) · 2.56 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package dnasdk
import (
"encoding/json"
"fmt"
"strings"
)
const (
DNA_RPC_GETVERSION = "getversion"
DNA_RPC_GETTRANSACTION = "getrawtransaction"
DNA_RPC_SENDTRANSACTION = "sendrawtransaction"
DNA_RPC_GETBLOCK = "getblock"
DNA_RPC_GETBLOCKCOUNT = "getblockcount"
DNA_RPC_GETBLOCKHASH = "getblockhash"
DNA_RPC_GETUNSPENDOUTPUT = "getunspendoutput"
DNA_RPC_GETCURRENTBLOCKHASH = "getbestblockhash"
DNA_RPC_GETIDENTITYUPDATE = "getidentityupdate"
)
const (
DNA_API_GETCONNCOUNT = "/api/v1/node/connectioncount"
DNA_API_GETBLOCKBYHEIGHT = "/api/v1/block/details/height"
DNA_API_GETBLOCKBYHASH = "/api/v1/block/details/hash"
DNA_API_GETBLOCKCOUNT = "/api/v1/block/height"
DNA_API_GETTRANSACTION = "/api/v1/transaction"
DNA_API_GETASSET = "/api/v1/asset"
DNA_API_SENDTRANSACTION = "/api/v1/transaction"
//Api_Getconnectioncount = "/api/v1/node/connectioncount"
//Api_Getblockbyheight = "/api/v1/block/details/height/:height"
//Api_Getblockbyhash = "/api/v1/block/details/hash/:hash"
//Api_Getblockheight = "/api/v1/block/height"
//Api_Gettransaction = "/api/v1/transaction/:hash"
//Api_Getasset = "/api/v1/asset/:hash"
//Api_Restart = "/api/v1/restart"
//Api_SendRawTransaction = "/api/v1/transaction"
//Api_OauthServerAddr = "/api/v1/config/oauthserver/addr"
//Api_NoticeServerAddr = "/api/v1/config/noticeserver/addr"
//Api_NoticeServerState = "/api/v1/config/noticeserver/state"
)
type DNAJsonRpcRes struct {
Id string `json:"id"`
JsonRpc string `json:"jsonrpc"`
Result json.RawMessage `json:"result"`
}
const (
DnaRpcInvalidHash = "invalid hash"
DnaRpcInvalidBlock = "invalid block"
DnaRpcInvalidTransaction = "invalid transaction"
DnaRpcInvalidParameter = "invalid parameter"
DnaRpcUnknownBlock = "unknown block"
DnaRpcUnknownTransaction = "unknown transaction"
DnaRpcNil = "null"
DnaRpcUnsupported = "Unsupported"
DnaRpcInternalError = "internal error"
)
var DNARpcError map[string]string = map[string]string{
DnaRpcInvalidHash: "",
DnaRpcInvalidBlock: "",
DnaRpcInvalidTransaction: "",
DnaRpcInvalidParameter: "",
DnaRpcUnknownBlock: "",
DnaRpcUnknownTransaction: "",
DnaRpcUnsupported: "",
DnaRpcInternalError: "",
DnaRpcNil: "",
}
func (this *DNAJsonRpcRes) HandleResult() ([]byte, error) {
res := strings.Trim(string(this.Result), "\"")
_, ok := DNARpcError[res]
if ok {
return nil, fmt.Errorf(res)
}
return []byte(res), nil
}