mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/evm/internal/t8ntool: minor refactorings
This commit is contained in:
parent
2b67330782
commit
9e578a5149
1 changed files with 35 additions and 55 deletions
|
|
@ -273,89 +273,69 @@ func (t *txWithKey) UnmarshalJSON(input []byte) error {
|
||||||
// and secondly to read them with the standard tx json format
|
// and secondly to read them with the standard tx json format
|
||||||
func signUnsignedTransactions(txs []*txWithKey, signer types.Signer) (types.Transactions, error) {
|
func signUnsignedTransactions(txs []*txWithKey, signer types.Signer) (types.Transactions, error) {
|
||||||
var signedTxs []*types.Transaction
|
var signedTxs []*types.Transaction
|
||||||
for i, txWithKey := range txs {
|
for i, tx := range txs {
|
||||||
tx := txWithKey.tx
|
|
||||||
key := txWithKey.key
|
|
||||||
v, r, s := tx.RawSignatureValues()
|
|
||||||
if key != nil && v.BitLen()+r.BitLen()+s.BitLen() == 0 {
|
|
||||||
// This transaction needs to be signed
|
|
||||||
var (
|
var (
|
||||||
|
v, r, s = tx.tx.RawSignatureValues()
|
||||||
signed *types.Transaction
|
signed *types.Transaction
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
if txWithKey.protected {
|
if tx.key == nil || v.BitLen()+r.BitLen()+s.BitLen() != 0 {
|
||||||
signed, err = types.SignTx(tx, signer, key)
|
// Already signed
|
||||||
|
signedTxs = append(signedTxs, tx.tx)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// This transaction needs to be signed
|
||||||
|
if tx.protected {
|
||||||
|
signed, err = types.SignTx(tx.tx, signer, tx.key)
|
||||||
} else {
|
} else {
|
||||||
signed, err = types.SignTx(tx, types.FrontierSigner{}, key)
|
signed, err = types.SignTx(tx.tx, types.FrontierSigner{}, tx.key)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, NewError(ErrorJson, fmt.Errorf("tx %d: failed to sign tx: %v", i, err))
|
return nil, NewError(ErrorJson, fmt.Errorf("tx %d: failed to sign tx: %v", i, err))
|
||||||
}
|
}
|
||||||
signedTxs = append(signedTxs, signed)
|
signedTxs = append(signedTxs, signed)
|
||||||
} else {
|
|
||||||
// Already signed
|
|
||||||
signedTxs = append(signedTxs, tx)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return signedTxs, nil
|
return signedTxs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadTransactions(txStr string, inputData *input, env stEnv, chainConfig *params.ChainConfig) (types.Transactions, error) {
|
func loadTransactions(txStr string, inputData *input, env stEnv, chainConfig *params.ChainConfig) (types.Transactions, error) {
|
||||||
var txsWithKeys []*txWithKey
|
var txsWithKeys []*txWithKey
|
||||||
|
var signed types.Transactions
|
||||||
if txStr != stdinSelector {
|
if txStr != stdinSelector {
|
||||||
inFile, err := os.Open(txStr)
|
data, err := os.ReadFile(txStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, NewError(ErrorIO, fmt.Errorf("failed reading txs file: %v", err))
|
return nil, NewError(ErrorIO, fmt.Errorf("failed reading txs file: %v", err))
|
||||||
}
|
}
|
||||||
defer inFile.Close()
|
if strings.HasSuffix(txStr, ".rlp") { // A file containing an rlp list
|
||||||
decoder := json.NewDecoder(inFile)
|
|
||||||
if strings.HasSuffix(txStr, ".rlp") {
|
|
||||||
var body hexutil.Bytes
|
var body hexutil.Bytes
|
||||||
if err := decoder.Decode(&body); err != nil {
|
if err := json.Unmarshal(data, &body); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var txs types.Transactions
|
// Already signed transactions
|
||||||
if err := rlp.DecodeBytes(body, &txs); err != nil {
|
if err := rlp.DecodeBytes(body, &signed); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, tx := range txs {
|
return signed, nil
|
||||||
txsWithKeys = append(txsWithKeys, &txWithKey{
|
|
||||||
key: nil,
|
|
||||||
tx: tx,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} else {
|
if err := json.Unmarshal(data, &txsWithKeys); err != nil {
|
||||||
if err := decoder.Decode(&txsWithKeys); err != nil {
|
|
||||||
return nil, NewError(ErrorJson, fmt.Errorf("failed unmarshaling txs-file: %v", err))
|
return nil, NewError(ErrorJson, fmt.Errorf("failed unmarshaling txs-file: %v", err))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if len(inputData.TxRlp) > 0 {
|
if len(inputData.TxRlp) > 0 {
|
||||||
// Decode the body of already signed transactions
|
// Decode the body of already signed transactions
|
||||||
body := common.FromHex(inputData.TxRlp)
|
body := common.FromHex(inputData.TxRlp)
|
||||||
var txs types.Transactions
|
// Already signed transactions
|
||||||
if err := rlp.DecodeBytes(body, &txs); err != nil {
|
if err := rlp.DecodeBytes(body, &signed); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, tx := range txs {
|
return signed, nil
|
||||||
txsWithKeys = append(txsWithKeys, &txWithKey{
|
|
||||||
key: nil,
|
|
||||||
tx: tx,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// JSON encoded transactions
|
// JSON encoded transactions
|
||||||
txsWithKeys = inputData.Txs
|
txsWithKeys = inputData.Txs
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// We may have to sign the transactions.
|
// We may have to sign the transactions.
|
||||||
signer := types.MakeSigner(chainConfig, big.NewInt(int64(env.Number)), env.Timestamp)
|
signer := types.MakeSigner(chainConfig, big.NewInt(int64(env.Number)), env.Timestamp)
|
||||||
|
return signUnsignedTransactions(txsWithKeys, signer)
|
||||||
if txs, err := signUnsignedTransactions(txsWithKeys, signer); err != nil {
|
|
||||||
return nil, NewError(ErrorJson, fmt.Errorf("failed signing transactions: %v", err))
|
|
||||||
} else {
|
|
||||||
return txs, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyLondonChecks(env *stEnv, chainConfig *params.ChainConfig) error {
|
func applyLondonChecks(env *stEnv, chainConfig *params.ChainConfig) error {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue