add rosetta logs

pull/4065/head
haodi 3 years ago
parent 348817aa0d
commit 26c064dbca
  1. 71
      core/evm.go

@ -118,6 +118,20 @@ func CreateValidatorFn(ref *block.Header, chain ChainContext) vm.CreateValidator
} }
db.SetValidatorFlag(createValidator.ValidatorAddress) db.SetValidatorFlag(createValidator.ValidatorAddress)
db.SubBalance(createValidator.ValidatorAddress, createValidator.Amount) 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 return nil
} }
} }
@ -155,6 +169,22 @@ func DelegateFn(ref *block.Header, chain ChainContext) vm.DelegateFunc {
db.SubBalance(delegate.DelegatorAddress, balanceToBeDeducted) 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 { if len(fromLockedTokens) > 0 {
sortedKeys := []common.Address{} sortedKeys := []common.Address{}
for key := range fromLockedTokens { for key := range fromLockedTokens {
@ -182,6 +212,22 @@ func DelegateFn(ref *block.Header, chain ChainContext) vm.DelegateFunc {
Data: encodedRedelegationData, Data: encodedRedelegationData,
BlockNumber: ref.Number().Uint64(), 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 return nil
@ -195,6 +241,21 @@ func UndelegateFn(ref *block.Header, chain ChainContext) vm.UndelegateFunc {
if err != nil { if err != nil {
return err 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) return db.UpdateValidatorWrapperWithRevert(wrapper.Address, wrapper)
} }
} }
@ -229,6 +290,16 @@ func CollectRewardsFn(ref *block.Header, chain ChainContext) vm.CollectRewardsFu
BlockNumber: ref.Number().Uint64(), BlockNumber: ref.Number().Uint64(),
}) })
//add rosetta log
rosettaTracer.AddRosettaLog(
vm.CALL,
nil,
&vm.RosettaLogAddressItem{
Account: &collectRewards.DelegatorAddress,
},
totalRewards,
)
return nil return nil
} }
} }

Loading…
Cancel
Save