Skip to content

Commit b07deaf

Browse files
committed
save
1 parent 32de24a commit b07deaf

File tree

2 files changed

+188
-17
lines changed

2 files changed

+188
-17
lines changed

cmd/snapshots/genfromrpc/genfromrpc.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func makeRetryableTxFunc(commonTx *types.CommonTx, rawTx map[string]interface{})
343343
}
344344

345345
// GasFeeCap: expected as a hex string.
346-
if gasFeeCapHex, ok := rawTx["gasFeeCap"].(string); ok {
346+
if gasFeeCapHex, ok := rawTx["maxFeePerGas"].(string); ok {
347347
tx.GasFeeCap = convertHexToBigInt(gasFeeCapHex)
348348
}
349349

@@ -380,6 +380,12 @@ func makeRetryableTxFunc(commonTx *types.CommonTx, rawTx map[string]interface{})
380380
if retryDataHex, ok := rawTx["retryData"].(string); ok && len(retryDataHex) >= 2 && retryDataHex[:2] == "0x" {
381381
tx.RetryData = common.Hex2Bytes(retryDataHex[2:])
382382
}
383+
fmt.Println(tx)
384+
385+
// GasPrice: expected as a hex string.
386+
// if gasPriceHex, ok := rawTx["gasPrice"].(string); ok {
387+
// tx.Fee = convertHexToBigInt(gasPriceHex)
388+
// }
383389

384390
return tx
385391
}
@@ -401,7 +407,7 @@ func makeArbitrumRetryTx(commonTx *types.CommonTx, rawTx map[string]interface{})
401407
}
402408

403409
// GasFeeCap (expected as a hex string)
404-
if gasFeeCapHex, ok := rawTx["gasFeeCap"].(string); ok {
410+
if gasFeeCapHex, ok := rawTx["maxFeePerGas"].(string); ok {
405411
tx.GasFeeCap = convertHexToBigInt(gasFeeCapHex)
406412
}
407413

@@ -442,6 +448,7 @@ func makeArbitrumRetryTx(commonTx *types.CommonTx, rawTx map[string]interface{})
442448
if submissionFeeRefundHex, ok := rawTx["submissionFeeRefund"].(string); ok {
443449
tx.SubmissionFeeRefund = convertHexToBigInt(submissionFeeRefundHex)
444450
}
451+
fmt.Println(tx)
445452

446453
return tx
447454
}
@@ -467,7 +474,7 @@ func makeArbitrumContractTx(commonTx *types.CommonTx, rawTx map[string]interface
467474
}
468475

469476
// GasFeeCap (expected as a hex string)
470-
if gasFeeCapHex, ok := rawTx["gasFeeCap"].(string); ok {
477+
if gasFeeCapHex, ok := rawTx["maxFeePerGas"].(string); ok {
471478
tx.GasFeeCap = convertHexToBigInt(gasFeeCapHex)
472479
}
473480

@@ -509,7 +516,7 @@ func makeArbitrumUnsignedTx(commonTx *types.CommonTx, rawTx map[string]interface
509516
tx.Nonce = commonTx.Nonce
510517

511518
// GasFeeCap: expected as a hex string.
512-
if gasFeeCapHex, ok := rawTx["gasFeeCap"].(string); ok {
519+
if gasFeeCapHex, ok := rawTx["maxFeePerGas"].(string); ok {
513520
tx.GasFeeCap = convertHexToBigInt(gasFeeCapHex)
514521
}
515522

@@ -580,6 +587,7 @@ func unMarshalTransactions(rawTxs []map[string]interface{}, arbitrum bool) (type
580587
if !ok {
581588
return nil, errors.New("missing tx type")
582589
}
590+
fmt.Println(typeTx)
583591

584592
switch typeTx {
585593
case "0x0": // Legacy
@@ -619,6 +627,7 @@ func unMarshalTransactions(rawTxs []map[string]interface{}, arbitrum bool) (type
619627
default:
620628
return nil, fmt.Errorf("unknown tx type: %s", typeTx)
621629
}
630+
fmt.Println(tx.Hash())
622631
txs = append(txs, tx)
623632

624633
}

core/types/arb_types.go

+175-13
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,16 @@ func (tx *ArbitrumUnsignedTx) WithSignature(signer Signer, sig []byte) (Transact
156156

157157
func (tx *ArbitrumUnsignedTx) Hash() common.Hash {
158158
//TODO implement me
159-
panic("implement me")
159+
return prefixedRlpHash(ArbitrumUnsignedTxType, []interface{}{
160+
tx.ChainId,
161+
tx.From,
162+
tx.Nonce,
163+
tx.GasFeeCap,
164+
tx.Gas,
165+
tx.To,
166+
tx.Value,
167+
tx.Data,
168+
})
160169
}
161170

162171
func (tx *ArbitrumUnsignedTx) SigningHash(chainID *big.Int) common.Hash {
@@ -352,7 +361,16 @@ func (tx *ArbitrumContractTx) WithSignature(signer Signer, sig []byte) (Transact
352361

353362
func (tx *ArbitrumContractTx) Hash() common.Hash {
354363
//TODO implement me
355-
panic("implement me")
364+
return prefixedRlpHash(ArbitrumContractTxType, []interface{}{
365+
tx.ChainId,
366+
tx.RequestId,
367+
tx.From,
368+
tx.GasFeeCap,
369+
tx.Gas,
370+
tx.To,
371+
tx.Value,
372+
tx.Data,
373+
})
356374
}
357375

358376
func (tx *ArbitrumContractTx) SigningHash(chainID *big.Int) common.Hash {
@@ -551,7 +569,20 @@ func (tx *ArbitrumRetryTx) WithSignature(signer Signer, sig []byte) (Transaction
551569

552570
func (tx *ArbitrumRetryTx) Hash() common.Hash {
553571
//TODO implement me
554-
panic("implement me")
572+
return prefixedRlpHash(ArbitrumRetryTxType, []interface{}{
573+
tx.ChainId,
574+
tx.Nonce,
575+
tx.From,
576+
tx.GasFeeCap,
577+
tx.Gas,
578+
tx.To,
579+
tx.Value,
580+
tx.Data,
581+
tx.TicketId,
582+
tx.RefundTo,
583+
tx.MaxRefund,
584+
tx.SubmissionFeeRefund,
585+
})
555586
}
556587

557588
func (tx *ArbitrumRetryTx) SigningHash(chainID *big.Int) common.Hash {
@@ -773,7 +804,7 @@ func (tx *ArbitrumSubmitRetryableTx) RawSignatureValues() (*uint256.Int, *uint25
773804
return uintZero, uintZero, uintZero
774805
}
775806

776-
func (tx *ArbitrumSubmitRetryableTx) payloadSize() int {
807+
func (tx *ArbitrumSubmitRetryableTx) payloadSize() (payloadSize int, gasLen int) {
777808
size := 0
778809
size++
779810
size += rlp.BigIntLenExcludingHead(tx.ChainId)
@@ -788,7 +819,8 @@ func (tx *ArbitrumSubmitRetryableTx) payloadSize() int {
788819
size++
789820
size += rlp.BigIntLenExcludingHead(tx.GasFeeCap)
790821
size++
791-
size += rlp.IntLenExcludingHead(tx.Gas)
822+
gasLen = rlp.IntLenExcludingHead(tx.Gas)
823+
size += gasLen
792824
size++
793825
if tx.RetryTo != nil {
794826
size += 20
@@ -802,10 +834,108 @@ func (tx *ArbitrumSubmitRetryableTx) payloadSize() int {
802834
size++
803835
size += 20
804836
size += rlp.StringLen(tx.RetryData)
805-
return size
837+
return size, gasLen
806838
}
807839

808-
func (tx *LegacyTx) encodePayload(w io.Writer, b []byte, payloadSize, nonceLen, gasLen int) error {
840+
func (tx *ArbitrumSubmitRetryableTx) encodePayload(w io.Writer, b []byte, payloadSize, gasLen int) error {
841+
// Write the RLP list prefix.
842+
if err := rlp.EncodeStructSizePrefix(payloadSize, w, b); err != nil {
843+
return err
844+
}
845+
846+
// ChainId (big.Int)
847+
if err := rlp.EncodeBigInt(tx.ChainId, w, b); err != nil {
848+
return err
849+
}
850+
851+
// RequestId (common.Hash, 32 bytes)
852+
b[0] = 128 + 32
853+
if _, err := w.Write(b[:1]); err != nil {
854+
return err
855+
}
856+
if _, err := w.Write(tx.RequestId[:]); err != nil {
857+
return err
858+
}
859+
860+
// From (common.Address, 20 bytes)
861+
b[0] = 128 + 20
862+
if _, err := w.Write(b[:1]); err != nil {
863+
return err
864+
}
865+
if _, err := w.Write(tx.From[:]); err != nil {
866+
return err
867+
}
868+
869+
// L1BaseFee (big.Int)
870+
if err := rlp.EncodeBigInt(tx.L1BaseFee, w, b); err != nil {
871+
return err
872+
}
873+
874+
// DepositValue (big.Int)
875+
if err := rlp.EncodeBigInt(tx.DepositValue, w, b); err != nil {
876+
return err
877+
}
878+
879+
// GasFeeCap (big.Int)
880+
if err := rlp.EncodeBigInt(tx.GasFeeCap, w, b); err != nil {
881+
return err
882+
}
883+
884+
// Gas (uint64)
885+
if err := rlp.EncodeInt(tx.Gas, w, b); err != nil {
886+
return err
887+
}
888+
889+
// RetryTo (pointer to common.Address, 20 bytes if non-nil; otherwise RLP nil)
890+
if tx.RetryTo == nil {
891+
b[0] = 128
892+
if _, err := w.Write(b[:1]); err != nil {
893+
return err
894+
}
895+
} else {
896+
b[0] = 128 + 20
897+
if _, err := w.Write(b[:1]); err != nil {
898+
return err
899+
}
900+
if _, err := w.Write((*tx.RetryTo)[:]); err != nil {
901+
return err
902+
}
903+
}
904+
905+
// RetryValue (big.Int)
906+
if err := rlp.EncodeBigInt(tx.RetryValue, w, b); err != nil {
907+
return err
908+
}
909+
910+
// Beneficiary (common.Address, 20 bytes)
911+
b[0] = 128 + 20
912+
if _, err := w.Write(b[:1]); err != nil {
913+
return err
914+
}
915+
if _, err := w.Write(tx.Beneficiary[:]); err != nil {
916+
return err
917+
}
918+
919+
// MaxSubmissionFee (big.Int)
920+
if err := rlp.EncodeBigInt(tx.MaxSubmissionFee, w, b); err != nil {
921+
return err
922+
}
923+
924+
// FeeRefundAddr (common.Address, 20 bytes)
925+
b[0] = 128 + 20
926+
if _, err := w.Write(b[:1]); err != nil {
927+
return err
928+
}
929+
if _, err := w.Write(tx.FeeRefundAddr[:]); err != nil {
930+
return err
931+
}
932+
933+
// RetryData ([]byte)
934+
if err := rlp.EncodeString(tx.RetryData, w, b); err != nil {
935+
return err
936+
}
937+
938+
return nil
809939
}
810940

811941
func (tx *ArbitrumSubmitRetryableTx) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Message, error) {
@@ -819,8 +949,21 @@ func (tx *ArbitrumSubmitRetryableTx) WithSignature(signer Signer, sig []byte) (T
819949
}
820950

821951
func (tx *ArbitrumSubmitRetryableTx) Hash() common.Hash {
822-
//TODO implement me
823-
panic("implement me")
952+
return prefixedRlpHash(ArbitrumSubmitRetryableTxType, []interface{}{
953+
tx.ChainId,
954+
tx.RequestId,
955+
tx.From,
956+
tx.L1BaseFee,
957+
tx.DepositValue,
958+
tx.GasFeeCap,
959+
tx.Gas,
960+
tx.RetryTo,
961+
tx.RetryValue,
962+
tx.Beneficiary,
963+
tx.MaxSubmissionFee,
964+
tx.FeeRefundAddr,
965+
tx.RetryData,
966+
})
824967
}
825968

826969
func (tx *ArbitrumSubmitRetryableTx) SigningHash(chainID *big.Int) common.Hash {
@@ -849,8 +992,18 @@ func (tx *ArbitrumSubmitRetryableTx) DecodeRLP(s *rlp.Stream) error {
849992
}
850993

851994
func (tx *ArbitrumSubmitRetryableTx) MarshalBinary(w io.Writer) error {
852-
//TODO implement me
853-
panic("implement me")
995+
payloadSize, gasLen := tx.payloadSize()
996+
b := newEncodingBuf()
997+
defer pooledBuf.Put(b)
998+
// encode TxType
999+
b[0] = ArbitrumSubmitRetryableTxType
1000+
if _, err := w.Write(b[:1]); err != nil {
1001+
return err
1002+
}
1003+
if err := tx.encodePayload(w, b[:], payloadSize, gasLen); err != nil {
1004+
return err
1005+
}
1006+
return nil
8541007
}
8551008

8561009
func (tx *ArbitrumSubmitRetryableTx) Sender(signer Signer) (common.Address, error) {
@@ -987,7 +1140,13 @@ func (d *ArbitrumDepositTx) WithSignature(signer Signer, sig []byte) (Transactio
9871140

9881141
func (d *ArbitrumDepositTx) Hash() common.Hash {
9891142
//TODO implement me
990-
panic("implement me")
1143+
return prefixedRlpHash(ArbitrumDepositTxType, []interface{}{
1144+
d.ChainId,
1145+
d.L1RequestId,
1146+
d.From,
1147+
d.To,
1148+
d.Value,
1149+
})
9911150
}
9921151

9931152
func (d *ArbitrumDepositTx) SigningHash(chainID *big.Int) common.Hash {
@@ -1129,7 +1288,10 @@ func (tx *ArbitrumInternalTx) WithSignature(signer Signer, sig []byte) (Transact
11291288

11301289
func (tx *ArbitrumInternalTx) Hash() common.Hash {
11311290
//TODO implement me
1132-
panic("implement me")
1291+
return prefixedRlpHash(ArbitrumInternalTxType, []interface{}{
1292+
tx.ChainId,
1293+
tx.Data,
1294+
})
11331295
}
11341296

11351297
func (tx *ArbitrumInternalTx) SigningHash(chainID *big.Int) common.Hash {

0 commit comments

Comments
 (0)