-
Notifications
You must be signed in to change notification settings - Fork 178
/
account.go
68 lines (56 loc) · 1.66 KB
/
account.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
package models
import (
"github.com/onflow/flow-go/engine/access/rest/util"
"github.com/onflow/flow-go/model/flow"
)
const expandableKeys = "keys"
const expandableContracts = "contracts"
func (a *Account) Build(flowAccount *flow.Account, link LinkGenerator, expand map[string]bool) error {
a.Address = flowAccount.Address.String()
a.Balance = util.FromUint64(flowAccount.Balance)
a.Expandable = &AccountExpandable{}
if expand[expandableKeys] {
var keys AccountPublicKeys
keys.Build(flowAccount.Keys)
a.Keys = keys
} else {
a.Expandable.Keys = expandableKeys
}
if expand[expandableContracts] {
contracts := make(map[string]string, len(flowAccount.Contracts))
for name, code := range flowAccount.Contracts {
contracts[name] = util.ToBase64(code)
}
a.Contracts = contracts
} else {
a.Expandable.Contracts = expandableContracts
}
var self Links
err := self.Build(link.AccountLink(a.Address))
if err != nil {
return err
}
a.Links = &self
return nil
}
func (a *AccountPublicKey) Build(k flow.AccountPublicKey) {
sigAlgo := SigningAlgorithm(k.SignAlgo.String())
hashAlgo := HashingAlgorithm(k.HashAlgo.String())
a.Index = util.FromUint64(uint64(k.Index))
a.PublicKey = k.PublicKey.String()
a.SigningAlgorithm = &sigAlgo
a.HashingAlgorithm = &hashAlgo
a.SequenceNumber = util.FromUint64(k.SeqNumber)
a.Weight = util.FromUint64(uint64(k.Weight))
a.Revoked = k.Revoked
}
type AccountPublicKeys []AccountPublicKey
func (a *AccountPublicKeys) Build(accountKeys []flow.AccountPublicKey) {
keys := make([]AccountPublicKey, len(accountKeys))
for i, k := range accountKeys {
var key AccountPublicKey
key.Build(k)
keys[i] = key
}
*a = keys
}