forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
static_service.go
56 lines (44 loc) · 1.34 KB
/
static_service.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
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package spchainvm
import (
"errors"
"net/http"
"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/utils/formatting"
"github.com/ava-labs/gecko/utils/json"
)
var (
errAccountHasNoValue = errors.New("account has no value")
)
// StaticService defines the static API exposed by the payments vm
type StaticService struct{}
// APIAccount ...
type APIAccount struct {
Address ids.ShortID `json:"address"`
Balance json.Uint64 `json:"balance"`
}
// BuildGenesisArgs are arguments for BuildGenesis
type BuildGenesisArgs struct {
Accounts []APIAccount `json:"accounts"`
}
// BuildGenesisReply is the reply from BuildGenesis
type BuildGenesisReply struct {
Bytes formatting.CB58 `json:"bytes"`
}
// BuildGenesis returns the UTXOs such that at least one address in [args.Addresses] is
// referenced in the UTXO.
func (*StaticService) BuildGenesis(_ *http.Request, args *BuildGenesisArgs, reply *BuildGenesisReply) error {
b := Builder{}
accounts := []Account(nil)
for _, account := range args.Accounts {
if account.Balance == 0 {
return errAccountHasNoValue
}
accounts = append(accounts, b.NewAccount(account.Address, 0, uint64(account.Balance)))
}
c := Codec{}
bytes, err := c.MarshalGenesis(accounts)
reply.Bytes.Bytes = bytes
return err
}