-
Notifications
You must be signed in to change notification settings - Fork 178
/
utils.go
43 lines (38 loc) · 1010 Bytes
/
utils.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
package migrations
import (
"fmt"
"github.com/onflow/flow-go/engine/execution/state"
"github.com/onflow/flow-go/ledger"
"github.com/onflow/flow-go/model/flow"
)
func keyToRegisterID(key ledger.Key) (flow.RegisterID, error) {
if len(key.KeyParts) != 3 ||
key.KeyParts[0].Type != state.KeyPartOwner ||
key.KeyParts[1].Type != state.KeyPartController ||
key.KeyParts[2].Type != state.KeyPartKey {
return flow.RegisterID{}, fmt.Errorf("key not in expected format %s", key.String())
}
return flow.NewRegisterID(
string(key.KeyParts[0].Value),
string(key.KeyParts[1].Value),
string(key.KeyParts[2].Value),
), nil
}
func registerIDToKey(registerID flow.RegisterID) ledger.Key {
newKey := ledger.Key{}
newKey.KeyParts = []ledger.KeyPart{
{
Type: state.KeyPartOwner,
Value: []byte(registerID.Owner),
},
{
Type: state.KeyPartController,
Value: []byte(registerID.Controller),
},
{
Type: state.KeyPartKey,
Value: []byte(registerID.Key),
},
}
return newKey
}