segments.go 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package vm
  2. import "math/big"
  3. type jumpSeg struct {
  4. pos uint64
  5. err error
  6. gas *big.Int
  7. }
  8. func (j jumpSeg) do(program *Program, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) ([]byte, error) {
  9. if !contract.UseGas(j.gas) {
  10. return nil, OutOfGasError
  11. }
  12. if j.err != nil {
  13. return nil, j.err
  14. }
  15. *pc = j.pos
  16. return nil, nil
  17. }
  18. func (s jumpSeg) halts() bool { return false }
  19. func (s jumpSeg) Op() OpCode { return 0 }
  20. type pushSeg struct {
  21. data []*big.Int
  22. gas *big.Int
  23. }
  24. func (s pushSeg) do(program *Program, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) ([]byte, error) {
  25. // Use the calculated gas. When insufficient gas is present, use all gas and return an
  26. // Out Of Gas error
  27. if !contract.UseGas(s.gas) {
  28. return nil, OutOfGasError
  29. }
  30. for _, d := range s.data {
  31. stack.push(new(big.Int).Set(d))
  32. }
  33. *pc += uint64(len(s.data))
  34. return nil, nil
  35. }
  36. func (s pushSeg) halts() bool { return false }
  37. func (s pushSeg) Op() OpCode { return 0 }