-
Notifications
You must be signed in to change notification settings - Fork 12
/
tx.go
56 lines (51 loc) · 1.42 KB
/
tx.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
/*
* Copyright (C) 2018-2019 Fusion Foundation Ltd. All rights reserved.
* Copyright (C) 2018-2019 gaozhengxin@fusion.org
*
* This library is free software; you can redistribute it and/or
* modify it under the Apache License, Version 2.0.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package omni
import (
"encoding/json"
"fmt"
"math/big"
"strings"
)
type RpcResult struct {
Result OmniTx `json:"result"`
Error string `json:"error"`
}
type OmniTx struct {
Confirmations int64 `json:"confirmations"`
Fee string `json:"fee"`
Valid bool `json:"valid"`
From string `json:"sendingaddress"`
To string `json:"referenceaddress"`
AmountString string `json:"amount"`
Amount *big.Int
Type string `json:"type"`
PropertyName string `json:"propertyname"`
PropertyId float64 `json:"propertyid"`
Error error
}
func DecodeOmniTx(ret string) (*OmniTx) {
var res = new(RpcResult)
json.Unmarshal([]byte(ret), res)
omnitx := res.Result
if res.Error != "" {
omnitx.Error = fmt.Errorf(res.Error)
}
s := strings.Replace(omnitx.AmountString,".","",-1)
omnitx.Amount, _ = new(big.Int).SetString(s,10)
omnitx.PropertyName = "OMNI"+omnitx.PropertyName
return &omnitx
}