-
Notifications
You must be signed in to change notification settings - Fork 46
/
init.go
54 lines (49 loc) · 1.53 KB
/
init.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
package multisig
import (
"github.com/iov-one/weave"
"github.com/iov-one/weave/errors"
)
// Initializer fulfils the Initializer interface to load data from the genesis
// file
type Initializer struct{}
var _ weave.Initializer = (*Initializer)(nil)
// FromGenesis will parse initial account info from genesis and save it in the
// database.
func (*Initializer) FromGenesis(opts weave.Options, params weave.GenesisParams, kv weave.KVStore) error {
var contracts []struct {
Participants []struct {
Signature weave.Address `json:"signature"`
Weight Weight `json:"weight"`
} `json:"participants"`
ActivationThreshold Weight `json:"activation_threshold"`
AdminThreshold Weight `json:"admin_threshold"`
}
if err := opts.ReadOptions("multisig", &contracts); err != nil {
return err
}
bucket := NewContractBucket()
for i, c := range contracts {
ps := make([]*Participant, 0, len(c.Participants))
for _, p := range c.Participants {
ps = append(ps, &Participant{
Signature: p.Signature,
Weight: p.Weight,
})
}
key, err := contractSeq.NextVal(kv)
if err != nil {
return errors.Wrap(err, "cannot acquire ID")
}
contract := Contract{
Metadata: &weave.Metadata{Schema: 1},
Participants: ps,
ActivationThreshold: c.ActivationThreshold,
AdminThreshold: c.AdminThreshold,
Address: MultiSigCondition(key).Address(),
}
if _, err := bucket.Put(kv, key, &contract); err != nil {
return errors.Wrapf(err, "cannot save #%d contract", i)
}
}
return nil
}