Skip to content

Commit

Permalink
fix: AttributesDeposited encode for ecotone
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod committed Mar 8, 2024
1 parent fe8243f commit 5fa2850
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))));
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 5fa2850

Please sign in to comment.