-
Notifications
You must be signed in to change notification settings - Fork 25
/
transaction.go
46 lines (43 loc) · 1.13 KB
/
transaction.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
package hitbtc
import (
"encoding/json"
"time"
)
// Transaction represents a transaction of money incoming or leaving the user account.
type Transaction struct {
Id string `json:"id"`
Index uint64 `json:"index"`
Currency string `json:"currency"`
Amount float64 `json:"amount,string"`
Fee float64 `json:"fee,string"`
NetworkFee float64 `json:"networkFee,string"`
Address string `json:"address"`
Hash string `json:"hash"`
Status string `json:"status"`
Type string `json:"type"`
Created time.Time `json:"createdAt"`
Updated time.Time `json:"updatedAt"`
}
func (t *Transaction) UnmarshalJSON(data []byte) error {
var err error
type Alias Transaction
aux := &struct {
Created string `json:"createdAt"`
Updated string `json:"updatedAt"`
*Alias
}{
Alias: (*Alias)(t),
}
if err = json.Unmarshal(data, &aux); err != nil {
return err
}
t.Created, err = time.Parse("2006-01-02T15:04:05.999Z", aux.Created)
if err != nil {
return err
}
t.Updated, err = time.Parse("2006-01-02T15:04:05.999Z", aux.Updated)
if err != nil {
return err
}
return nil
}