forked from Layr-Labs/eigenda-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package wvm | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
"strings" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
) | ||
|
||
type Web3SignerTransactionData struct { | ||
bytesData []byte | ||
chainID int64 | ||
fromAddress common.Address | ||
toAddress common.Address | ||
gasLimit uint64 | ||
gasFeeCap *big.Int | ||
nonce uint64 | ||
} | ||
|
||
func NewWeb3SignerTransactionData(fromAddress, toAddress common.Address, | ||
gasLimit uint64, gasFeeCap *big.Int, data string, nonce uint64, chainID int64, | ||
) (*Web3SignerTransactionData, error) { | ||
// Prepare data payload. | ||
var hexData string | ||
if strings.HasPrefix(data, "0x") { | ||
hexData = data | ||
} else { | ||
hexData = hexutil.Encode([]byte(data)) | ||
} | ||
bytesData, err := hexutil.Decode(hexData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Web3SignerTransactionData{ | ||
bytesData: bytesData, | ||
chainID: chainID, | ||
fromAddress: fromAddress, | ||
toAddress: toAddress, | ||
gasLimit: gasLimit, | ||
gasFeeCap: gasFeeCap, | ||
nonce: nonce, | ||
}, nil | ||
} | ||
|
||
func (data *Web3SignerTransactionData) ToRequestMap() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"from": data.fromAddress.String(), | ||
"to": data.toAddress.String(), | ||
"gas": fmt.Sprintf("0x%x", data.gasLimit), | ||
"maxFeePerGas": fmt.Sprintf("0x%x", data.gasFeeCap), | ||
"maxPriorityFeePerGas": "0x0", | ||
"value": "0x0", | ||
"data": data.bytesData, | ||
"nonce": fmt.Sprintf("0x%x", data.nonce), | ||
"chainId": fmt.Sprintf("0x%x", data.chainID), | ||
} | ||
} | ||
|
||
type SignTransactionResponse string | ||
|
||
func (r *SignTransactionResponse) UnmarshalJSON(data []byte) error { | ||
var signedTx string | ||
if err := json.Unmarshal(data, &signedTx); err != nil { | ||
return err | ||
} | ||
*r = SignTransactionResponse(signedTx) | ||
return nil | ||
} | ||
|
||
type RetrieverResponse struct { | ||
ArweaveBlockHash string `json:"arweave_block_hash"` | ||
Calldata string `json:"calldata"` | ||
WarDecodedCalldata string `json:"war_decoded_calldata"` | ||
WvmBlockHash string `json:"wvm_block_hash"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters