Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support typed transaction #35

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.