Skip to content

Commit

Permalink
Merge pull request #33 from KyberNetwork/feat/revert-pending-tx
Browse files Browse the repository at this point in the history
feat: revert pkg/types/pendingtx.go
  • Loading branch information
tiennampham23 authored Mar 28, 2024
2 parents 712fb8f + a54979f commit d444ea1
Showing 1 changed file with 0 additions and 129 deletions.
129 changes: 0 additions & 129 deletions pkg/types/pendingtx.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package types

import (
"encoding/json"
"math/big"

"github.com/KyberNetwork/tradinglib/pkg/mev"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
)
Expand Down Expand Up @@ -57,133 +55,6 @@ type CallFrame struct {
ContractCall *ContractCall `json:"contract_call,omitempty"`
}

type CallLog struct {
Address common.Address `json:"address"`
Topics []common.Hash `json:"topics"`
Data hexutil.Bytes `json:"data"`
}

func (c CallFrame) TypeString() string {
return c.Type.String()
}

// MarshalJSON marshals as JSON.
func (c CallFrame) MarshalJSON() ([]byte, error) {
type CallFrame0 struct {
Type vm.OpCode `json:"-"`
From common.Address `json:"from"`
Gas hexutil.Uint64 `json:"gas"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
To *common.Address `json:"to,omitempty"`
Input hexutil.Bytes `json:"input"`
Output hexutil.Bytes `json:"output,omitempty"`
Error string `json:"error,omitempty"`
RevertReason string `json:"revertReason,omitempty"`
Calls []*CallFrame `json:"calls,omitempty"`
Logs []*CallLog `json:"logs,omitempty"`
Value *hexutil.Big `json:"value,omitempty"`
TypeString string `json:"type"`
ContractCall *ContractCall `json:"contract_call,omitempty"`
}
var enc CallFrame0
enc.Type = c.Type
enc.From = c.From
enc.Gas = hexutil.Uint64(c.Gas)
enc.GasUsed = hexutil.Uint64(c.GasUsed)
enc.To = c.To
enc.Input = c.Input
enc.Output = c.Output
enc.Error = c.Error
enc.RevertReason = c.RevertReason
enc.Calls = c.Calls
if c.Logs != nil {
logs := make([]*CallLog, 0, len(c.Logs))
for _, log := range c.Logs {
logs = append(logs, &CallLog{
Address: log.Address,
Topics: log.Topics,
Data: log.Data,
})
}
enc.Logs = logs
}
enc.Value = (*hexutil.Big)(c.Value)
enc.TypeString = c.TypeString()
enc.ContractCall = c.ContractCall
return json.Marshal(&enc)
}

// UnmarshalJSON unmarshals from JSON.
func (c *CallFrame) UnmarshalJSON(input []byte) error {
type CallFrame0 struct {
Type *vm.OpCode `json:"-"`
From *common.Address `json:"from"`
Gas *hexutil.Uint64 `json:"gas"`
GasUsed *hexutil.Uint64 `json:"gasUsed"`
To *common.Address `json:"to,omitempty"`
Input *hexutil.Bytes `json:"input"`
Output *hexutil.Bytes `json:"output,omitempty"`
Error *string `json:"error,omitempty"`
RevertReason *string `json:"revertReason,omitempty"`
Calls []*CallFrame `json:"calls,omitempty"`
Logs []*CallLog `json:"logs,omitempty"`
Value *hexutil.Big `json:"value,omitempty"`
ContractCall *ContractCall `json:"contract_call,omitempty"`
}
var dec CallFrame0
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.Type != nil {
c.Type = *dec.Type
}
if dec.From != nil {
c.From = *dec.From
}
if dec.Gas != nil {
c.Gas = uint64(*dec.Gas)
}
if dec.GasUsed != nil {
c.GasUsed = uint64(*dec.GasUsed)
}
if dec.To != nil {
c.To = dec.To
}
if dec.Input != nil {
c.Input = *dec.Input
}
if dec.Output != nil {
c.Output = *dec.Output
}
if dec.Error != nil {
c.Error = *dec.Error
}
if dec.RevertReason != nil {
c.RevertReason = *dec.RevertReason
}
if dec.Calls != nil {
c.Calls = dec.Calls
}

if dec.Value != nil {
c.Value = (*big.Int)(dec.Value)
}
if dec.ContractCall != nil {
c.ContractCall = dec.ContractCall
}

logs := make([]*types.Log, 0, len(dec.Logs))
for _, log := range dec.Logs {
logs = append(logs, &types.Log{
Address: log.Address,
Topics: log.Topics,
Data: log.Data,
})
}
c.Logs = logs
return nil
}

type ContractCallParam struct {
Name string `json:"name"`
Value interface{} `json:"value"`
Expand Down

0 comments on commit d444ea1

Please sign in to comment.