Skip to content

Commit

Permalink
Standardize interfaces between objects and JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
iamalwaysuncomfortable committed Jan 16, 2025
1 parent 4ba13dc commit 1b0f732
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 68 deletions.
12 changes: 8 additions & 4 deletions sdk/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { BlockJSON, Header, Metadata } from "./models/blockJSON";
import { ConfirmedTransactionJSON } from "./models/confirmed_transaction";
import { DeploymentJSON, VerifyingKeys } from "./models/deployment/deploymentJSON";
import { DeploymentObject } from "./models/deployment/deploymentObject";
import { ExecutionJSON } from "./models/executionJSON";
import { FeeJSON} from "./models/feeJSON";
import { ExecutionJSON, FeeExecutionJSON } from "./models/execution/executionJSON";
import { ExecutionObject, FeeExecutionObject } from "./models/execution/executionObject";
import { FinalizeJSON } from "./models/finalizeJSON";
import { FunctionObject } from "./models/functionObject";
import { InputJSON } from "./models/input/inputJSON";
import { InputObject } from "./models/input/inputObject";
import { OutputJSON } from "./models/output/outputJSON";
import { OutputObject } from "./models/output/outputObject";
import { OwnerJSON } from "./models/ownerJSON";
import { OwnerJSON } from "./models/owner/ownerJSON";
import { PlaintextArray} from "./models/plaintext/array";
import { PlaintextLiteral} from "./models/plaintext/literal";
import { PlaintextObject } from "./models/plaintext/plaintext";
Expand Down Expand Up @@ -107,7 +108,10 @@ export {
DeploymentJSON,
DeploymentObject,
ExecutionJSON,
FeeJSON,
ExecutionObject,
FeeExecutionJSON,
FeeExecutionObject,
FinalizeJSON,
FunctionObject,
FunctionKeyPair,
FunctionKeyProvider,
Expand Down
13 changes: 13 additions & 0 deletions sdk/src/models/execution/executionJSON.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { TransitionJSON } from "../transition/transitionJSON";

export interface ExecutionJSON {
transitions: TransitionJSON[];
proof: string;
global_state_root: string;
}

export interface FeeExecutionJSON {
transition: TransitionJSON;
proof: string;
global_state_root: string;
}
13 changes: 13 additions & 0 deletions sdk/src/models/execution/executionObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { TransitionObject } from "../transition/transitionObject";

export interface ExecutionObject {
transitions: TransitionObject[];
proof: string;
global_state_root: string;
}

export interface FeeExecutionObject {
transition: TransitionObject;
proof: string;
global_state_root: string;
}
7 changes: 0 additions & 7 deletions sdk/src/models/executionJSON.ts

This file was deleted.

7 changes: 0 additions & 7 deletions sdk/src/models/feeJSON.ts

This file was deleted.

6 changes: 1 addition & 5 deletions sdk/src/models/input/inputJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@ export interface InputJSON {
type: string;
id: string;
tag?: string;
origin?: Origin;
value?: string;
}
export type Origin = {
commitment: string;
}
}
File renamed without changes.
6 changes: 6 additions & 0 deletions sdk/src/models/owner/ownerObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Address, Signature } from "../../wasm";

export interface OwnerObject {
address: string | Address;
signature: string | Signature;
}
3 changes: 2 additions & 1 deletion sdk/src/models/plaintext/plaintext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Plaintext } from "../../wasm";
import { PlaintextArray } from "./array";
import { PlaintextLiteral } from "./literal";
import { PlaintextStruct } from "./struct";

export type PlaintextObject = PlaintextArray| PlaintextLiteral | PlaintextStruct;
export type PlaintextObject = PlaintextArray| PlaintextLiteral | PlaintextStruct | Plaintext;
7 changes: 3 additions & 4 deletions sdk/src/models/transaction/transactionJSON.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { DeploymentJSON } from "../deployment/deploymentJSON";
import { ExecutionJSON } from "../executionJSON";
import { FeeJSON } from "../feeJSON";
import { OwnerJSON } from "../ownerJSON";
import { ExecutionJSON, FeeExecutionJSON } from "../execution/executionJSON";
import { OwnerJSON } from "../owner/ownerJSON";

export interface TransactionJSON {
type: string;
id: string;
deployment?: DeploymentJSON;
execution?: ExecutionJSON;
fee: FeeJSON;
fee: FeeExecutionJSON;
owner?: OwnerJSON;
}
15 changes: 9 additions & 6 deletions sdk/src/models/transaction/transactionObject.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { TransitionObject } from "../transition/transitionObject";
import { DeploymentObject } from "../deployment/deploymentObject";
import { ExecutionObject, FeeExecutionObject } from "../execution/executionObject";
import { OwnerObject } from "../owner/ownerObject";

export interface TransactionObject {
id : string;
type : string;
fee : bigint;
baseFee : bigint;
priorityFee : bigint;
transitions : TransitionObject[];
id : string;
execution?: ExecutionObject;
deployment? : DeploymentObject;
fee: FeeExecutionObject;
owner?: OwnerObject;
feeAmount? : bigint;
baseFee? : bigint;
priorityFee? : bigint;
}
33 changes: 21 additions & 12 deletions sdk/tests/network-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import sinon from "sinon";
import { expect } from "chai";
import { Account, BlockJSON, AleoNetworkClient, TransactionObject, InputObject, OutputObject } from "../src/node";
import {
Account,
BlockJSON,
AleoNetworkClient,
TransactionObject,
InputObject,
OutputObject,
ExecutionObject
} from "../src/node";
import { beaconPrivateKeyString } from "./data/account-data";
import { DeploymentObject, ExecutionJSON, InputJSON, OutputJSON, Plaintext, PlaintextObject, Transition, TransitionObject } from "../src/node";

Expand Down Expand Up @@ -274,20 +282,21 @@ describe('NodeConnection', () => {
expect(transition.scm().toString()).equals("4048085747685910464005835076598544744404883618916202014212851266936759881218field");

// Ensure the object summary returns the correct transaction metadata.
const execution = <ExecutionObject>summary.execution;
expect(summary.type).equals(transaction.transactionType());
expect(summary.fee).equals(transaction.feeAmount());
expect(summary.transitions.length).equals(2);
expect(<string>summary.transitions[0].tpk).equals("6666707959509237020554863505720154589525217196021270704042929032892063700604group");
expect(<string>summary.transitions[0].tcm).equals("5140704971235445395514301730284508935687584564904251867869912904008739082032field");
expect(<string>summary.transitions[0].scm).equals("4048085747685910464005835076598544744404883618916202014212851266936759881218field");
expect(summary.transitions[0].function).equals("mint");
expect(summary.feeAmount).equals(transaction.feeAmount());
expect(execution.transitions.length).equals(2);
expect(<string>execution.transitions[0].tpk).equals("6666707959509237020554863505720154589525217196021270704042929032892063700604group");
expect(<string>execution.transitions[0].tcm).equals("5140704971235445395514301730284508935687584564904251867869912904008739082032field");
expect(<string>execution.transitions[0].scm).equals("4048085747685910464005835076598544744404883618916202014212851266936759881218field");
expect(execution.transitions[0].function).equals("mint");
expect(summary.id).equals(transaction.id());
expect(summary.fee).equals(transaction.feeAmount());
expect(summary.feeAmount).equals(transaction.feeAmount());
expect(summary.baseFee).equals(transaction.baseFeeAmount());
expect(summary.priorityFee).equals(transaction.priorityFeeAmount());

// Check inputs.
const transition_summary = <TransitionObject>summary.transitions[0];
const transition_summary = <TransitionObject>execution.transitions[0];
const transition_inputs = <InputObject[]>transition_summary.inputs;
const transition_outputs = <OutputObject[]>transition_summary.outputs;
// Ensure the transition_summary matches the wasm object.
Expand Down Expand Up @@ -331,10 +340,10 @@ describe('NodeConnection', () => {

// Ensure the object summary returns the correct general transaction metadata.
expect(summary.type).equals(transaction.transactionType());
expect(summary.fee).equals(transaction.feeAmount());
expect(summary.transitions.length).equals(0);
expect(summary.feeAmount).equals(transaction.feeAmount());
expect(summary.execution).equals(null);
expect(summary.id).equals(transaction.id());
expect(summary.fee).equals(transaction.feeAmount());
expect(summary.feeAmount).equals(transaction.feeAmount());
expect(summary.baseFee).equals(transaction.baseFeeAmount());
expect(summary.priorityFee).equals(transaction.priorityFeeAmount());
expect(deployment.program).equals("token_registry.aleo");
Expand Down
Loading

0 comments on commit 1b0f732

Please sign in to comment.