From 5fa2850ff7f9e8c304eb4e519a3a058ffb9985a4 Mon Sep 17 00:00:00 2001 From: thinkAfCod Date: Fri, 8 Mar 2024 17:29:31 +0800 Subject: [PATCH] fix: AttributesDeposited encode for ecotone --- .../io/optimism/derive/stages/Attributes.java | 15 ++++---- .../stages/AttributesDepositedTest.java | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 hildr-node/src/test/java/io/optimism/derive/stages/AttributesDepositedTest.java diff --git a/hildr-node/src/main/java/io/optimism/derive/stages/Attributes.java b/hildr-node/src/main/java/io/optimism/derive/stages/Attributes.java index 89fe7ae1..038e1a49 100644 --- a/hildr-node/src/main/java/io/optimism/derive/stages/Attributes.java +++ b/hildr-node/src/main/java/io/optimism/derive/stages/Attributes.java @@ -29,9 +29,7 @@ import org.slf4j.LoggerFactory; import org.web3j.abi.TypeEncoder; import org.web3j.abi.datatypes.Uint; -import org.web3j.abi.datatypes.generated.Bytes32; -import org.web3j.abi.datatypes.generated.Uint256; -import org.web3j.abi.datatypes.generated.Uint64; +import org.web3j.abi.datatypes.generated.*; import org.web3j.crypto.Hash; import org.web3j.protocol.core.methods.response.EthBlock; import org.web3j.protocol.core.methods.response.EthLog.LogObject; @@ -381,11 +379,12 @@ public byte[] encode() { public byte[] encodeInEcotone() { StringBuilder sb = new StringBuilder(); sb.append("440a5e20"); - sb.append(TypeEncoder.encode(new Uint(this.baseFeeScalar))); - sb.append(TypeEncoder.encode(new Uint(this.blobBaseFeeScalar))); - sb.append(TypeEncoder.encode(new Uint64(this.sequenceNumber))); - sb.append(TypeEncoder.encode(new Uint64(this.timestamp))); - sb.append(TypeEncoder.encode(new Uint64(this.number))); + sb.append(Numeric.toHexStringNoPrefixZeroPadded(this.baseFeeScalar, 8)); + sb.append(Numeric.toHexStringNoPrefixZeroPadded(this.blobBaseFeeScalar, 8)); + sb.append(Numeric.toHexStringNoPrefixZeroPadded(this.sequenceNumber, 16)); + sb.append(Numeric.toHexStringNoPrefixZeroPadded(this.timestamp, 16)); + sb.append(Numeric.toHexStringNoPrefixZeroPadded(this.number, 16)); + sb.append(TypeEncoder.encode(new Uint256(this.baseFee))); sb.append(TypeEncoder.encode(new Uint256(this.blobBaseFee))); sb.append(TypeEncoder.encode(new Bytes32(Numeric.hexStringToByteArray(this.hash)))); diff --git a/hildr-node/src/test/java/io/optimism/derive/stages/AttributesDepositedTest.java b/hildr-node/src/test/java/io/optimism/derive/stages/AttributesDepositedTest.java new file mode 100644 index 00000000..0fc75644 --- /dev/null +++ b/hildr-node/src/test/java/io/optimism/derive/stages/AttributesDepositedTest.java @@ -0,0 +1,37 @@ +package io.optimism.derive.stages; + +import java.math.BigInteger; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.web3j.utils.Numeric; + +/** + * The type AttributesDepositedTest. + * + * @author thinkAfCod + * @since 0.2.7 + */ +public class AttributesDepositedTest { + + @Test + void testEncode() { + Attributes.AttributesDeposited deposited = new Attributes.AttributesDeposited( + BigInteger.valueOf(5335397L), + BigInteger.valueOf(1708534716L), + new BigInteger("9476942369"), + "0xe680e3ec5290b08570531865205fe15ddc5dbac1f55b4156e2444e77f36d97f4", + BigInteger.valueOf(5L), + "0x0000000000000000000000008f23bb38f531600e5d8fddaaec41f13fab46e98c", + null, + null, + null, + new BigInteger("25177585170"), + BigInteger.valueOf(684000L), + BigInteger.valueOf(0L), + false); + byte[] bytes = deposited.encodeInEcotone(); + Assertions.assertEquals( + "0x440a5e20000a6fe00000000000000000000000050000000065d62bbc00000000005169650000000000000000000000000000000000000000000000000000000234deaa2100000000000000000000000000000000000000000000000000000005dcb37612e680e3ec5290b08570531865205fe15ddc5dbac1f55b4156e2444e77f36d97f40000000000000000000000008f23bb38f531600e5d8fddaaec41f13fab46e98c", + Numeric.toHexString(bytes)); + } +}