From 26c064dbca20d583b020981bf64d568a1173b7a8 Mon Sep 17 00:00:00 2001 From: haodi <82733821@qq.com> Date: Sat, 19 Feb 2022 17:59:55 +0800 Subject: [PATCH] add rosetta logs --- core/evm.go | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/core/evm.go b/core/evm.go index befb56007..92812ab5d 100644 --- a/core/evm.go +++ b/core/evm.go @@ -118,6 +118,20 @@ func CreateValidatorFn(ref *block.Header, chain ChainContext) vm.CreateValidator } db.SetValidatorFlag(createValidator.ValidatorAddress) db.SubBalance(createValidator.ValidatorAddress, createValidator.Amount) + + //add rosetta log + rosettaTracer.AddRosettaLog( + vm.CALL, + &vm.RosettaLogAddressItem{ + Account: &createValidator.ValidatorAddress, + }, + &vm.RosettaLogAddressItem{ + Account: &createValidator.ValidatorAddress, + SubAccount: &createValidator.ValidatorAddress, + Metadata: map[string]interface{}{"type": "delegation"}, + }, + createValidator.Amount, + ) return nil } } @@ -155,6 +169,22 @@ func DelegateFn(ref *block.Header, chain ChainContext) vm.DelegateFunc { db.SubBalance(delegate.DelegatorAddress, balanceToBeDeducted) + if balanceToBeDeducted != big.NewInt(0) { + //add rosetta log + rosettaTracer.AddRosettaLog( + vm.CALL, + &vm.RosettaLogAddressItem{ + Account: &delegate.DelegatorAddress, + }, + &vm.RosettaLogAddressItem{ + Account: &delegate.DelegatorAddress, + SubAccount: &delegate.ValidatorAddress, + Metadata: map[string]interface{}{"type": "delegation"}, + }, + balanceToBeDeducted, + ) + } + if len(fromLockedTokens) > 0 { sortedKeys := []common.Address{} for key := range fromLockedTokens { @@ -182,6 +212,22 @@ func DelegateFn(ref *block.Header, chain ChainContext) vm.DelegateFunc { Data: encodedRedelegationData, BlockNumber: ref.Number().Uint64(), }) + + //add rosetta log + rosettaTracer.AddRosettaLog( + vm.CALL, + &vm.RosettaLogAddressItem{ + Account: &delegate.DelegatorAddress, + SubAccount: &key, + Metadata: map[string]interface{}{"type": "undelegation"}, + }, + &vm.RosettaLogAddressItem{ + Account: &delegate.DelegatorAddress, + SubAccount: &delegate.ValidatorAddress, + Metadata: map[string]interface{}{"type": "delegation"}, + }, + redelegatedToken, + ) } } return nil @@ -195,6 +241,21 @@ func UndelegateFn(ref *block.Header, chain ChainContext) vm.UndelegateFunc { if err != nil { return err } + + //add rosetta log + rosettaTracer.AddRosettaLog( + vm.CALL, + &vm.RosettaLogAddressItem{ + Account: &undelegate.DelegatorAddress, + }, + &vm.RosettaLogAddressItem{ + Account: &undelegate.DelegatorAddress, + SubAccount: &undelegate.ValidatorAddress, + Metadata: map[string]interface{}{"type": "undelegation"}, + }, + undelegate.Amount, + ) + return db.UpdateValidatorWrapperWithRevert(wrapper.Address, wrapper) } } @@ -229,6 +290,16 @@ func CollectRewardsFn(ref *block.Header, chain ChainContext) vm.CollectRewardsFu BlockNumber: ref.Number().Uint64(), }) + //add rosetta log + rosettaTracer.AddRosettaLog( + vm.CALL, + nil, + &vm.RosettaLogAddressItem{ + Account: &collectRewards.DelegatorAddress, + }, + totalRewards, + ) + return nil } }