Skip to content

Commit

Permalink
Support typed transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
bunnie307 committed Aug 16, 2023
1 parent 1992706 commit 32433bd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
17 changes: 15 additions & 2 deletions bmv/bsc2/src/main/java/foundation/icon/btp/bmv/bsc2/Receipt.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
import scorex.util.Collections;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;

public class Receipt {
public static final int StatusFailed = 0;
private static final int AccessListTx = 1;
private static final int DynamicFeeTx = 2;
private final byte[] postStatusOrState;
private final List<EventLog> logs;

Expand All @@ -35,7 +38,6 @@ public Receipt(byte[] postStatusOrState,
}

public static Receipt readObject(ObjectReader r) {
// TODO supports to decoding typed-receipt
r.beginList();
byte[] postStatusOrState = r.readByteArray();
r.readBigInteger();
Expand All @@ -51,7 +53,18 @@ public static Receipt readObject(ObjectReader r) {
}

public static Receipt fromBytes(byte[] bytes) {
return Receipt.readObject(Context.newByteArrayObjectReader("RLP", bytes));
Context.require(bytes.length > 0, "Invalid receipt bytes");

// legacy transaction
if ((bytes[0] & 0xff) > 0x7f) {
return Receipt.readObject(Context.newByteArrayObjectReader("RLP", bytes));
}

// typed transaction
Context.require(bytes[0] == AccessListTx || bytes[0] == DynamicFeeTx,
"Unsupported typed transaction");
return Receipt.readObject(Context.newByteArrayObjectReader("RLP",
Arrays.copyOfRange(bytes, 1, bytes.length)));
}

public int getStatus() {
Expand Down
55 changes: 55 additions & 0 deletions bmv/bsc2/src/test/resources/testnet.json

Large diffs are not rendered by default.

0 comments on commit 32433bd

Please sign in to comment.