-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathreceivable.go
More file actions
47 lines (40 loc) · 1.18 KB
/
receivable.go
File metadata and controls
47 lines (40 loc) · 1.18 KB
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
package atto
import (
"encoding/json"
)
// Receivable represents a block that is waiting to be received.
type Receivable struct {
Hash string
Amount string
Source string
}
type internalReceivable struct {
Error string `json:"error"`
Blocks receivableBlocks `json:"blocks"`
}
type receivableBlocks map[string]receivableBlock
// UnmarshalJSON just unmarshals a list of strings, but
// interprets an empty string as an empty list. This is
// necessary due to a bug in the Nano node implementation. See
// https://github.com/nanocurrency/nano-node/issues/3161.
func (b *receivableBlocks) UnmarshalJSON(in []byte) error {
if string(in) == `""` {
return nil
}
var raw map[string]receivableBlock
err := json.Unmarshal(in, &raw)
*b = receivableBlocks(raw)
return err
}
type receivableBlock struct {
Amount string `json:"amount"`
Source string `json:"source"`
}
func internalReceivableToReceivable(internalReceivable internalReceivable) []Receivable {
receivables := make([]Receivable, 0)
for hash, source := range internalReceivable.Blocks {
receivable := Receivable{hash, source.Amount, source.Source}
receivables = append(receivables, receivable)
}
return receivables
}