github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/environment/account_local_id_generator.go (about) 1 package environment 2 3 import ( 4 "github.com/onflow/cadence/runtime/common" 5 6 "github.com/onflow/flow-go/fvm/storage/state" 7 "github.com/onflow/flow-go/fvm/tracing" 8 "github.com/onflow/flow-go/model/flow" 9 "github.com/onflow/flow-go/module/trace" 10 ) 11 12 type AccountLocalIDGenerator interface { 13 GenerateAccountID(address common.Address) (uint64, error) 14 } 15 16 type ParseRestrictedAccountLocalIDGenerator struct { 17 txnState state.NestedTransactionPreparer 18 impl AccountLocalIDGenerator 19 } 20 21 func NewParseRestrictedAccountLocalIDGenerator( 22 txnState state.NestedTransactionPreparer, 23 impl AccountLocalIDGenerator, 24 ) AccountLocalIDGenerator { 25 return ParseRestrictedAccountLocalIDGenerator{ 26 txnState: txnState, 27 impl: impl, 28 } 29 } 30 31 func (generator ParseRestrictedAccountLocalIDGenerator) GenerateAccountID( 32 address common.Address, 33 ) (uint64, error) { 34 return parseRestrict1Arg1Ret( 35 generator.txnState, 36 trace.FVMEnvGenerateAccountLocalID, 37 generator.impl.GenerateAccountID, 38 address) 39 } 40 41 type accountLocalIDGenerator struct { 42 tracer tracing.TracerSpan 43 meter Meter 44 accounts Accounts 45 } 46 47 func NewAccountLocalIDGenerator( 48 tracer tracing.TracerSpan, 49 meter Meter, 50 accounts Accounts, 51 ) AccountLocalIDGenerator { 52 return &accountLocalIDGenerator{ 53 tracer: tracer, 54 meter: meter, 55 accounts: accounts, 56 } 57 } 58 59 func (generator *accountLocalIDGenerator) GenerateAccountID( 60 runtimeAddress common.Address, 61 ) ( 62 uint64, 63 error, 64 ) { 65 defer generator.tracer.StartExtensiveTracingChildSpan( 66 trace.FVMEnvGenerateAccountLocalID, 67 ).End() 68 69 err := generator.meter.MeterComputation(ComputationKindGenerateAccountLocalID, 1) 70 if err != nil { 71 return 0, err 72 } 73 74 return generator.accounts.GenerateAccountLocalID( 75 flow.ConvertAddress(runtimeAddress), 76 ) 77 }