Skip to content

Commit

Permalink
feat: transparent bindings and bigints (#919)
Browse files Browse the repository at this point in the history
Description
---
Handle the `#[serde(transparent)]` structs, and also fix the bigint. i64
and u64 were exported as bigint, instead of number. The number can hold
anything in range(inclusive) from -(2^53-1)...(2^53-1). Anything above
or below can be hold but it's not safe to be precise.

Motivation and Context
---
Some of the structures are `#[serde(transparent)]` this is not
recognized by the ts-rs crate. If the structure is "real struct" (e.g.
struct A{b:u64} and not a struct A(u64), then we can call #[ts(flatten)]
but you have to call it on every instance. And it will rewrite the
variable e.g.
```
struct A{
  #[ts(flatten)]
  b:B
}

struct B {
  c:u8
}
```
Will be exported as
```
export interface A {
  c : number; // instead of b : number
}
```
So I have decided instead of flatten define the types by hand 

How Has This Been Tested?
---

What process can a PR reviewer use to test or verify this change?
---


Breaking Changes
---

- [x] None
- [ ] Requires data directory to be deleted
- [ ] Other - Please specify
  • Loading branch information
Cifko authored Feb 7, 2024
1 parent c29d5b8 commit 0c6f6e9
Show file tree
Hide file tree
Showing 130 changed files with 285 additions and 316 deletions.
6 changes: 3 additions & 3 deletions bindings/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# SPDX-License-Identifier: BSD-3-Clause

cargo test --workspace --exclude integration_tests export_bindings --features ts
shx mv ../dan_layer/bindings/src/types/* ./src/types/
shx rm -rf ../dan_layer/bindings/
npx shx mv ../dan_layer/bindings/src/types/* ./src/types/
npx shx rm -rf ../dan_layer/bindings/
DIRECTORY_PATH="./src/types" # replace with your directory path
HELPERS_PATH="./src/helpers" # replace with your directory path
INDEX_FILE="./index.ts"

# Remove the index file if it exists
if [ -f "$INDEX_FILE" ]; then
rm "$INDEX_FILE"
npx shx rm "$INDEX_FILE"
fi

# Add the license header
Expand Down
11 changes: 0 additions & 11 deletions bindings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export * from "./src/types/AccountsListResponse";
export * from "./src/types/AddAddressRequest";
export * from "./src/types/AddPeerRequest";
export * from "./src/types/AddPeerResponse";
export * from "./src/types/Amount";
export * from "./src/types/Arg";
export * from "./src/types/ArgDef";
export * from "./src/types/AuthGetAllJwtRequest";
Expand All @@ -37,9 +36,7 @@ export * from "./src/types/AuthLoginResponse";
export * from "./src/types/AuthRevokeTokenRequest";
export * from "./src/types/AuthRevokeTokenResponse";
export * from "./src/types/BalanceEntry";
export * from "./src/types/BalanceProofSignature";
export * from "./src/types/Block";
export * from "./src/types/BlockId";
export * from "./src/types/BucketId";
export * from "./src/types/CallInstructionRequest";
export * from "./src/types/ClaimBurnRequest";
Expand Down Expand Up @@ -69,7 +66,6 @@ export * from "./src/types/ConnectionDirection";
export * from "./src/types/Decision";
export * from "./src/types/DeleteAddressRequest";
export * from "./src/types/DryRunTransactionFinalizeResult";
export * from "./src/types/EncryptedData";
export * from "./src/types/Epoch";
export * from "./src/types/Event";
export * from "./src/types/Evidence";
Expand Down Expand Up @@ -119,7 +115,6 @@ export * from "./src/types/GetTransactionResultRequest";
export * from "./src/types/GetTransactionResultResponse";
export * from "./src/types/GetValidatorFeesRequest";
export * from "./src/types/GetValidatorFeesResponse";
export * from "./src/types/Hash";
export * from "./src/types/IndexedValue";
export * from "./src/types/IndexedWellKnownTypes";
export * from "./src/types/IndexerTransactionFinalizedResult";
Expand Down Expand Up @@ -156,15 +151,13 @@ export * from "./src/types/NonFungibleIndexAddress";
export * from "./src/types/NonFungibleSubstate";
export * from "./src/types/Ordering";
export * from "./src/types/OwnerRule";
export * from "./src/types/PedersonCommitmentBytes";
export * from "./src/types/ProofId";
export * from "./src/types/ProofsCancelRequest";
export * from "./src/types/ProofsCancelResponse";
export * from "./src/types/ProofsFinalizeRequest";
export * from "./src/types/ProofsFinalizeResponse";
export * from "./src/types/ProofsGenerateRequest";
export * from "./src/types/ProofsGenerateResponse";
export * from "./src/types/QcId";
export * from "./src/types/QuorumCertificate";
export * from "./src/types/QuorumDecision";
export * from "./src/types/RegisterValidatorNodeRequest";
Expand All @@ -179,12 +172,10 @@ export * from "./src/types/ResourceType";
export * from "./src/types/RestrictedAccessRule";
export * from "./src/types/RevealFundsRequest";
export * from "./src/types/RevealFundsResponse";
export * from "./src/types/RistrettoPublicKeyBytes";
export * from "./src/types/RuleRequirement";
export * from "./src/types/SettingsGetResponse";
export * from "./src/types/SettingsSetRequest";
export * from "./src/types/SettingsSetResponse";
export * from "./src/types/Shard";
export * from "./src/types/ShardEvidence";
export * from "./src/types/SubmitTransactionRequest";
export * from "./src/types/SubmitTransactionResponse";
Expand All @@ -210,7 +201,6 @@ export * from "./src/types/TransactionGetRequest";
export * from "./src/types/TransactionGetResponse";
export * from "./src/types/TransactionGetResultRequest";
export * from "./src/types/TransactionGetResultResponse";
export * from "./src/types/TransactionId";
export * from "./src/types/TransactionReceipt";
export * from "./src/types/TransactionReceiptAddress";
export * from "./src/types/TransactionResult";
Expand All @@ -224,7 +214,6 @@ export * from "./src/types/TransferRequest";
export * from "./src/types/TransferResponse";
export * from "./src/types/Type";
export * from "./src/types/UnclaimedConfidentialOutput";
export * from "./src/types/UnclaimedConfidentialOutputAddress";
export * from "./src/types/ValidatorFee";
export * from "./src/types/ValidatorNode";
export * from "./src/types/ValidatorSignature";
Expand Down
5 changes: 2 additions & 3 deletions bindings/src/types/AccountsCreateFreeTestCoinsRequest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";
import type { ComponentAddressOrName } from "./ComponentAddressOrName";

export interface AccountsCreateFreeTestCoinsRequest {
account: ComponentAddressOrName | null;
amount: Amount;
max_fee: Amount | null;
amount: number;
max_fee: number | null;
key_id: number | null;
}
8 changes: 3 additions & 5 deletions bindings/src/types/AccountsCreateFreeTestCoinsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";
import type { FinalizeResult } from "./FinalizeResult";
import type { TransactionId } from "./TransactionId";

export interface AccountsCreateFreeTestCoinsResponse {
transaction_id: TransactionId;
amount: Amount;
fee: Amount;
transaction_id: string;
amount: number;
fee: number;
result: FinalizeResult;
public_key: string;
}
5 changes: 2 additions & 3 deletions bindings/src/types/AccountsCreateRequest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";
import type { ComponentAccessRules } from "./ComponentAccessRules";

export interface AccountsCreateRequest {
account_name: string | null;
custom_access_rules: ComponentAccessRules | null;
max_fee: Amount | null;
max_fee: number | null;
is_default: boolean;
key_id: bigint | null;
key_id: number | null;
}
3 changes: 1 addition & 2 deletions bindings/src/types/AccountsInvokeRequest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";
import type { Arg } from "./Arg";
import type { ComponentAddressOrName } from "./ComponentAddressOrName";

export interface AccountsInvokeRequest {
account: ComponentAddressOrName | null;
method: string;
args: Array<Arg>;
max_fee: Amount | null;
max_fee: number | null;
}
2 changes: 1 addition & 1 deletion bindings/src/types/AccountsListResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import type { AccountInfo } from "./AccountInfo";

export interface AccountsListResponse {
accounts: Array<AccountInfo>;
total: bigint;
total: number;
}
3 changes: 0 additions & 3 deletions bindings/src/types/Amount.ts

This file was deleted.

5 changes: 2 additions & 3 deletions bindings/src/types/BalanceEntry.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";
import type { ResourceAddress } from "./ResourceAddress";
import type { ResourceType } from "./ResourceType";
import type { SubstateId } from "./SubstateId";

export interface BalanceEntry {
vault_address: SubstateId;
resource_address: ResourceAddress;
balance: Amount;
balance: number;
resource_type: ResourceType;
confidential_balance: Amount;
confidential_balance: number;
token_symbol: string | null;
}
3 changes: 0 additions & 3 deletions bindings/src/types/BalanceProofSignature.ts

This file was deleted.

11 changes: 5 additions & 6 deletions bindings/src/types/Block.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { BlockId } from "./BlockId";
import type { Command } from "./Command";
import type { Epoch } from "./Epoch";
import type { NodeHeight } from "./NodeHeight";
import type { QuorumCertificate } from "./QuorumCertificate";
import type { Shard } from "./Shard";

export interface Block {
id: BlockId;
parent: BlockId;
id: string;
network: string;
parent: string;
justify: QuorumCertificate;
height: NodeHeight;
epoch: Epoch;
proposed_by: string;
total_leader_fee: bigint;
total_leader_fee: number;
merkle_root: string;
commands: Array<Command>;
is_dummy: boolean;
is_processed: boolean;
is_committed: boolean;
foreign_indexes: Record<Shard, bigint>;
foreign_indexes: Array<{ shard: string; counter: number }>;
stored_at: string | null;
signature: { public_nonce: string; signature: string } | null;
}
3 changes: 0 additions & 3 deletions bindings/src/types/BlockId.ts

This file was deleted.

2 changes: 1 addition & 1 deletion bindings/src/types/CallInstructionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface CallInstructionRequest {
override_inputs: boolean | null;
new_outputs: number | null;
is_dry_run: boolean;
proof_ids: Array<bigint>;
proof_ids: Array<number>;
min_epoch: number | null;
max_epoch: number | null;
}
3 changes: 1 addition & 2 deletions bindings/src/types/ClaimBurnRequest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";
import type { ComponentAddressOrName } from "./ComponentAddressOrName";

export interface ClaimBurnRequest {
account: ComponentAddressOrName | null;
claim_proof: string;
max_fee: Amount | null;
max_fee: number | null;
key_id: number | null;
}
6 changes: 2 additions & 4 deletions bindings/src/types/ClaimBurnResponse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";
import type { FinalizeResult } from "./FinalizeResult";
import type { TransactionId } from "./TransactionId";

export interface ClaimBurnResponse {
transaction_id: TransactionId;
fee: Amount;
transaction_id: string;
fee: number;
result: FinalizeResult;
}
3 changes: 1 addition & 2 deletions bindings/src/types/ClaimValidatorFeesRequest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";
import type { ComponentAddressOrName } from "./ComponentAddressOrName";
import type { Epoch } from "./Epoch";

export interface ClaimValidatorFeesRequest {
account: ComponentAddressOrName | null;
max_fee: Amount | null;
max_fee: number | null;
validator_public_key: string;
epoch: Epoch;
dry_run: boolean;
Expand Down
6 changes: 2 additions & 4 deletions bindings/src/types/ClaimValidatorFeesResponse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";
import type { FinalizeResult } from "./FinalizeResult";
import type { TransactionId } from "./TransactionId";

export interface ClaimValidatorFeesResponse {
transaction_id: TransactionId;
fee: Amount;
transaction_id: string;
fee: number;
result: FinalizeResult;
}
3 changes: 1 addition & 2 deletions bindings/src/types/CommitteeShard.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Shard } from "./Shard";

export interface CommitteeShard {
num_committees: number;
num_members: number;
shard: Shard;
shard: number;
}
3 changes: 1 addition & 2 deletions bindings/src/types/CommitteeShardInfo.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Shard } from "./Shard";
import type { SubstateAddress } from "./SubstateAddress";
import type { ValidatorNode } from "./ValidatorNode";

export interface CommitteeShardInfo<TAddr> {
shard: Shard;
shard: number;
substate_address_range: { start: SubstateAddress; end: SubstateAddress };
validators: Array<ValidatorNode<TAddr>>;
}
1 change: 1 addition & 0 deletions bindings/src/types/ComponentAccessRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
import type { AccessRule } from "./AccessRule";

export interface ComponentAccessRules {
method_access: Record<string, AccessRule>;
default: AccessRule;
}
3 changes: 1 addition & 2 deletions bindings/src/types/ComponentHeader.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ComponentAccessRules } from "./ComponentAccessRules";
import type { ComponentBody } from "./ComponentBody";
import type { Hash } from "./Hash";
import type { OwnerRule } from "./OwnerRule";

export interface ComponentHeader {
template_address: Hash;
template_address: string;
module_name: string;
owner_key: string;
owner_rule: OwnerRule;
Expand Down
3 changes: 1 addition & 2 deletions bindings/src/types/ConfidentialClaim.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ConfidentialWithdrawProof } from "./ConfidentialWithdrawProof";
import type { UnclaimedConfidentialOutputAddress } from "./UnclaimedConfidentialOutputAddress";

export interface ConfidentialClaim {
public_key: string;
output_address: UnclaimedConfidentialOutputAddress;
output_address: string;
range_proof: Array<number>;
proof_of_knowledge: string;
withdraw_proof: ConfidentialWithdrawProof | null;
Expand Down
3 changes: 1 addition & 2 deletions bindings/src/types/ConfidentialCreateOutputProofRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";

export interface ConfidentialCreateOutputProofRequest {
amount: Amount;
amount: number;
}
5 changes: 2 additions & 3 deletions bindings/src/types/ConfidentialOutput.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { EncryptedData } from "./EncryptedData";

export interface ConfidentialOutput {
commitment: string;
stealth_public_nonce: string;
encrypted_data: EncryptedData;
minimum_value_promise: bigint;
encrypted_data: Array<number>;
minimum_value_promise: number;
}
11 changes: 4 additions & 7 deletions bindings/src/types/ConfidentialStatement.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";
import type { EncryptedData } from "./EncryptedData";
import type { RistrettoPublicKeyBytes } from "./RistrettoPublicKeyBytes";

export interface ConfidentialStatement {
commitment: Array<number>;
sender_public_nonce: RistrettoPublicKeyBytes;
encrypted_data: EncryptedData;
minimum_value_promise: bigint;
revealed_amount: Amount;
sender_public_nonce: Array<number>;
encrypted_data: Array<number>;
minimum_value_promise: number;
revealed_amount: number;
}
5 changes: 2 additions & 3 deletions bindings/src/types/ConfidentialTransferRequest.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Amount } from "./Amount";
import type { ComponentAddressOrName } from "./ComponentAddressOrName";
import type { ResourceAddress } from "./ResourceAddress";

export interface ConfidentialTransferRequest {
account: ComponentAddressOrName | null;
amount: Amount;
amount: number;
resource_address: ResourceAddress;
destination_public_key: string;
max_fee: Amount | null;
max_fee: number | null;
dry_run: boolean;
}
Loading

0 comments on commit 0c6f6e9

Please sign in to comment.