-
Notifications
You must be signed in to change notification settings - Fork 175
/
account_local_id_generator.go
77 lines (66 loc) · 1.71 KB
/
account_local_id_generator.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
69
70
71
72
73
74
75
76
77
package environment
import (
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/flow-go/fvm/storage/state"
"github.com/onflow/flow-go/fvm/tracing"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/trace"
)
type AccountLocalIDGenerator interface {
GenerateAccountID(address common.Address) (uint64, error)
}
type ParseRestrictedAccountLocalIDGenerator struct {
txnState state.NestedTransactionPreparer
impl AccountLocalIDGenerator
}
func NewParseRestrictedAccountLocalIDGenerator(
txnState state.NestedTransactionPreparer,
impl AccountLocalIDGenerator,
) AccountLocalIDGenerator {
return ParseRestrictedAccountLocalIDGenerator{
txnState: txnState,
impl: impl,
}
}
func (generator ParseRestrictedAccountLocalIDGenerator) GenerateAccountID(
address common.Address,
) (uint64, error) {
return parseRestrict1Arg1Ret(
generator.txnState,
trace.FVMEnvGenerateAccountLocalID,
generator.impl.GenerateAccountID,
address)
}
type accountLocalIDGenerator struct {
tracer tracing.TracerSpan
meter Meter
accounts Accounts
}
func NewAccountLocalIDGenerator(
tracer tracing.TracerSpan,
meter Meter,
accounts Accounts,
) AccountLocalIDGenerator {
return &accountLocalIDGenerator{
tracer: tracer,
meter: meter,
accounts: accounts,
}
}
func (generator *accountLocalIDGenerator) GenerateAccountID(
runtimeAddress common.Address,
) (
uint64,
error,
) {
defer generator.tracer.StartExtensiveTracingChildSpan(
trace.FVMEnvGenerateAccountLocalID,
).End()
err := generator.meter.MeterComputation(ComputationKindGenerateAccountLocalID, 1)
if err != nil {
return 0, err
}
return generator.accounts.GenerateAccountLocalID(
flow.ConvertAddress(runtimeAddress),
)
}