Skip to content

Commit

Permalink
Update TransactionOnNetwork to follow specs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Dec 19, 2024
1 parent be16a79 commit 3645a29
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
14 changes: 10 additions & 4 deletions src/networkProviders/providers.dev.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,18 @@ describe("test network providers on devnet: Proxy and API", function () {
) {
// Proxy and API exhibit differences in the "function" field, in case of move-balance transactions.
apiResponse.function = proxyResponse.function;

apiResponse.raw = {};
apiResponse.smartContractResults.map((x) => (x.raw = {}));
apiResponse.smartContractResults.map((x) => x.logs.events.map((e) => (e.raw = {})));
apiResponse.logs.events.map((e) => (e.raw = {}));
// Ignore fields which are not present on API response:
proxyResponse.epoch = 0;
proxyResponse.blockNonce = 0;
proxyResponse.hyperblockNonce = 0;
proxyResponse.hyperblockHash = "";
proxyResponse.blockHash = "";
proxyResponse.miniblockHash = "";
proxyResponse.raw = {};
proxyResponse.smartContractResults.map((x) => (x.raw = {}));
proxyResponse.smartContractResults.map((x) => x.logs.events.map((e) => (e.raw = {})));
proxyResponse.logs.events.map((e) => (e.raw = {}));
}

it("should have the same response for transactions with events", async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("test smart contract transactions outcome parser", () => {
const parser = new SmartContractTransactionsOutcomeParser();

const transactionOnNetwork = new TransactionOnNetwork({
nonce: 7,
nonce: 7n,
logs: new TransactionLogs({
events: [
new TransactionEvent({
Expand Down Expand Up @@ -52,7 +52,7 @@ describe("test smart contract transactions outcome parser", () => {
const parser = new SmartContractTransactionsOutcomeParser();

const transactionOnNetwork = new TransactionOnNetwork({
nonce: 7,
nonce: 7n,
logs: new TransactionLogs({
events: [
new TransactionEvent({
Expand All @@ -77,7 +77,7 @@ describe("test smart contract transactions outcome parser", () => {
it("parses execute outcome, without ABI", function () {
const parser = new SmartContractTransactionsOutcomeParser();
const transactionOnNetwork = new TransactionOnNetwork({
nonce: 7,
nonce: 7n,
smartContractResults: [new SmartContractResult({ data: Buffer.from("@6f6b@2a") })],
});

Expand All @@ -94,7 +94,7 @@ describe("test smart contract transactions outcome parser", () => {
});

const transactionOnNetwork = new TransactionOnNetwork({
nonce: 7,
nonce: 7n,
function: "getUltimateAnswer",
smartContractResults: [new SmartContractResult({ data: Buffer.from("@6f6b@2a") })],
});
Expand All @@ -113,7 +113,7 @@ describe("test smart contract transactions outcome parser", () => {
});

const transactionOnNetwork = new TransactionOnNetwork({
nonce: 7,
nonce: 7n,
smartContractResults: [new SmartContractResult({ data: Buffer.from("@6f6b@2a") })],
});

Expand Down
3 changes: 2 additions & 1 deletion src/transactionEvents.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Address } from "./address";

export class TransactionEvent {
raw: Record<string, any> = {};
address: Address = Address.empty();
identifier: string = "";
topics: Uint8Array[] = [];
Expand All @@ -25,8 +26,8 @@ export class TransactionEvent {
result.topics = (responsePart.topics || []).map((topic) => Buffer.from(topic, "base64"));

result.data = Buffer.from(responsePart.data ?? "", "base64");

result.additionalData = (responsePart.additionalData || []).map((data) => Buffer.from(data, "base64"));
result.raw = responsePart;

return result;
}
Expand Down
41 changes: 23 additions & 18 deletions src/transactionOnNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,29 @@ export function prepareTransactionForBroadcasting(transaction: Transaction): any
}

export class TransactionOnNetwork {
raw: Record<string, any> = {};
isCompleted?: boolean;
hash: string = "";
type: string = "";
nonce: number = 0;
round: number = 0;
nonce: bigint = 0n;
round: bigint = 0n;
epoch: number = 0;
value: string = "";
value: bigint = 0n;
receiver: Address = Address.empty();
sender: Address = Address.empty();
gasLimit: number = 0;
gasPrice: number = 0;
senderShard: number = 0;
receiverShard: number = 0;
gasLimit: bigint = 0n;
gasPrice: bigint = 0n;
function: string = "";
data: Buffer = Buffer.from([]);
version: number = 0;
options: number = 0;
signature: string = "";
status: TransactionStatus = TransactionStatus.createUnknown();
timestamp: number = 0;

blockNonce: number = 0;
hyperblockNonce: number = 0;
hyperblockHash: string = "";
miniblockHash: string = "";
blockHash: string = "";

smartContractResults: SmartContractResult[] = [];
logs: TransactionLogs = new TransactionLogs();
Expand Down Expand Up @@ -105,23 +108,25 @@ export class TransactionOnNetwork {
let result = new TransactionOnNetwork();
result.hash = txHash;
result.type = response.type || "";
result.nonce = response.nonce || 0;
result.round = response.round;
result.nonce = BigInt(response.nonce || 0);
result.round = BigInt(response.round || 0);
result.epoch = response.epoch || 0;
result.value = (response.value || 0).toString();
result.value = BigInt((response.value || 0).toString());
result.sender = new Address(response.sender);
result.receiver = new Address(response.receiver);
result.gasPrice = response.gasPrice || 0;
result.gasLimit = response.gasLimit || 0;
result.gasPrice = BigInt(response.gasPrice) || 0n;
result.gasLimit = BigInt(response.gasLimit) || 0n;
result.function = response.function || "";
result.data = Buffer.from(response.data || "", "base64");
result.version = response.version || 1;
result.options = response.options || 0;
result.data = Buffer.from(response.data || "", "base64");
result.status = new TransactionStatus(response.status);
result.timestamp = response.timestamp || 0;

result.blockNonce = response.blockNonce || 0;
result.hyperblockNonce = response.hyperblockNonce || 0;
result.hyperblockHash = response.hyperblockHash || "";
result.miniblockHash = response.miniblockHash || "";
result.blockHash = response.blockHash || "";
result.logs = TransactionLogs.fromHttpResponse(response.logs || {});
// result.raw = response;

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("test transaction events parser", () => {
});

const transactionOnNetwork = new TransactionOnNetwork({
nonce: 7,
nonce: 7n,
smartContractResults: [
new SmartContractResult({
data: Buffer.from("@6f6b"),
Expand Down Expand Up @@ -92,7 +92,7 @@ describe("test transaction events parser", () => {
});

const transactionOnNetwork = new TransactionOnNetwork({
nonce: 7,
nonce: 7n,
smartContractResults: [new SmartContractResult({ data: Buffer.from("@6f6b") })],
logs: new TransactionLogs({
events: [
Expand Down

0 comments on commit 3645a29

Please sign in to comment.