Guest User

Untitled

a guest
Jun 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. if (m_ext->balance(m_ext->myAddress) >= callParams->valueTransfer && m_ext->depth < 1024)
  2. {
  3. callParams->onOp = m_onOp;
  4. callParams->senderAddress = m_OP == Instruction::DELEGATECALL ? m_ext->caller : m_ext->myAddress; // if Delegatecall the sender address and value stays the same
  5. // STATICCALL is rejected by !m_schedule->haveStaticCall elsewhere
  6. callParams->receiveAddress = (m_OP == Instruction::CALL || m_OP == Instruction::STATICCALL) ? callParams->codeAddress : m_ext->myAddress; // if opcode isn’t CALL, the target address to call is the current one.
  7. callParams->data = bytesConstRef(m_mem.data() + inOff, inSize);
  8. o_output = bytesRef(m_mem.data() + outOff, outSize);
  9. return true;
  10. }
  11. return false;
  12.  
  13. func execDelegateCall(env vm.Environment, caller vm.ContractRef, originAddr, toAddr, codeAddr *common.Address, codeHash common.Hash, input, code []byte, gas, gasPrice, value *big.Int) (ret []byte, addr common.Address, err error) {
  14. evm := env.Vm()
  15. // Depth check execution. Fail if we're trying to execute above the
  16. // limit.
  17. if env.Depth() > callCreateDepthMax {
  18. caller.ReturnGas(gas, gasPrice)
  19. return nil, common.Address{}, errCallCreateDepth
  20. }
  21.  
  22. snapshot := env.SnapshotDatabase()
  23.  
  24. var to vm.Account
  25. if !env.Db().Exist(*toAddr) {
  26. to = env.Db().CreateAccount(*toAddr)
  27. } else {
  28. to = env.Db().GetAccount(*toAddr)
  29. }
  30.  
  31. // Iinitialise a new contract and make initialise the delegate values
  32. contract := vm.NewContract(caller, to, value, gas, gasPrice).AsDelegate()
  33. contract.SetCallCode(codeAddr, codeHash, code)
  34. defer contract.Finalise()
  35.  
  36. ret, err = evm.Run(contract, input)
  37. if err != nil {
  38. contract.UseGas(contract.Gas)
  39.  
  40. env.RevertToSnapshot(snapshot)
  41. }
  42.  
  43. return ret, addr, err
  44. }
  45.  
  46. // AsDelegate sets the contract to be a delegate call and returns the current
  47. // contract (for chaining calls)
  48. func (c *Contract) AsDelegate() *Contract {
  49. c.DelegateCall = true
  50. // NOTE: caller must, at all times be a contract. It should never happen
  51. // that caller is something other than a Contract.
  52. c.CallerAddress = c.caller.(*Contract).CallerAddress
  53. return c
  54. }
Add Comment
Please, Sign In to add comment