Skip to content

Commit

Permalink
update the path, add helpers, fix some types
Browse files Browse the repository at this point in the history
  • Loading branch information
Cifko committed Jan 29, 2024
1 parent 8d9db0d commit 4baff13
Show file tree
Hide file tree
Showing 301 changed files with 577 additions and 501 deletions.
16 changes: 13 additions & 3 deletions bindings/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cargo test --workspace --exclude integration_tests export_bindings --features ts
shx mv ../dan_layer/bindings/src/* ./src/
shx mv ../dan_layer/bindings/src/types/* ./src/types/
shx rm -rf ../dan_layer/bindings/
DIRECTORY_PATH="./src" # replace with your directory path
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
Expand All @@ -18,4 +19,13 @@ for file in $(find $DIRECTORY_PATH -name "*.ts"); do
fi
done

npx prettier --write "./**/*.{ts,tsx,css,json}"
# Add helpers
for file in $(find $HELPERS_PATH -name "*.ts"); do
FILE_NAME=$(basename $file)
if [ "$FILE_NAME" != "index.ts" ]; then
MODULE_NAME="${FILE_NAME%.*}"
echo "export * from '$HELPERS_PATH/$MODULE_NAME';" >> $INDEX_FILE
fi
done

npx prettier --write "./**/*.{ts,tsx,css,json}" --log-level=warn
463 changes: 232 additions & 231 deletions bindings/index.ts

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions bindings/src/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { RejectReason } from "../types/RejectReason";
import { SubstateId } from "../types/SubstateId";

export function substateIdToString(substateId: SubstateId): string {
if ("Component" in substateId) {
return substateId.Component;
}
if ("Resource" in substateId) {
return substateId.Resource;
}
if ("Vault" in substateId) {
return substateId.Vault;
}
if ("UnclaimedConfidentialOutput" in substateId) {
return substateId.UnclaimedConfidentialOutput;
}
if ("NonFungible" in substateId) {
return substateId.NonFungible;
}
if ("NonFungibleIndex" in substateId) {
return `${substateId.NonFungibleIndex.resource_address}:${substateId.NonFungibleIndex.index}`;
}
if ("TransactionReceipt" in substateId) {
return substateId.TransactionReceipt;
}
if ("FeeClaim" in substateId) {
return substateId.FeeClaim;
}
console.error("Unknown substate id", substateId);
return "Unknown";
}

export function rejectReasonToString(reason: RejectReason): string {
if (typeof reason === "string") {
return reason;
}
if ("ShardsNotPledged" in reason) {
return reason.ShardsNotPledged;
}
if ("ExecutionFailure" in reason) {
return reason.ExecutionFailure;
}
if ("ShardPledgedToAnotherPayload" in reason) {
return reason.ShardPledgedToAnotherPayload;
}
if ("ShardRejected" in reason) {
return reason.ShardRejected;
}
if ("FeesNotPaid" in reason) {
return reason.FeesNotPaid;
}
console.error("Unknown reason", reason);
return "Unknown";
}
File renamed without changes.
2 changes: 1 addition & 1 deletion bindings/src/Account.ts → bindings/src/types/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import type { SubstateId } from "./SubstateId";
export interface Account {
name: string | null;
address: SubstateId;
key_index: bigint;
key_index: number;
is_default: boolean;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface AccountNftInfo {
metadata: string;
metadata: any;
is_burned: boolean;
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export interface AccountsCreateFreeTestCoinsRequest {
account: ComponentAddressOrName | null;
amount: Amount;
max_fee: Amount | null;
key_id: bigint | null;
key_id: number | null;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface AccountsListRequest {
offset: bigint;
limit: bigint;
offset: number;
limit: number;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export interface ClaimBurnRequest {
account: ComponentAddressOrName | null;
claim_proof: string;
max_fee: Amount | null;
key_id: bigint | null;
key_id: number | null;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions bindings/src/Event.ts → bindings/src/types/Event.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ComponentAddress } from "./ComponentAddress";
import type { Hash } from "./Hash";
import type { Metadata } from "./Metadata";

export interface Event {
component_address: ComponentAddress | null;
template_address: Hash;
tx_hash: Hash;
template_address: string;
tx_hash: string;
topic: string;
payload: Metadata;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface KeysCreateRequest {
specific_index: bigint | null;
specific_index: number | null;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface KeysSetActiveRequest {
index: bigint;
index: number;
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface ListAccountNftRequest {
limit: bigint;
offset: bigint;
limit: number;
offset: number;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import type { ResourceAddress } from "./ResourceAddress";

export interface NonFungibleIndexAddress {
resource_address: ResourceAddress;
index: bigint;
index: number;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Hash } from "./Hash";

export type UnclaimedConfidentialOutputAddress = Hash;
export type UnclaimedConfidentialOutputAddress = string;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 24 additions & 24 deletions clients/tari_indexer_client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tari_transaction::{SubstateRequirement, Transaction, TransactionId};
use ts_rs::TS;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetSubstateRequest {
#[serde(with = "serde_tools::string")]
pub address: SubstateId,
Expand All @@ -30,7 +30,7 @@ pub struct GetSubstateRequest {
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetSubstateResponse {
#[serde(with = "serde_tools::string")]
pub address: SubstateId,
Expand All @@ -41,7 +41,7 @@ pub struct GetSubstateResponse {

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct InspectSubstateRequest {
#[serde_as(as = "DisplayFromStr")]
pub address: SubstateId,
Expand All @@ -50,7 +50,7 @@ pub struct InspectSubstateRequest {

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct InspectSubstateResponse {
#[serde_as(as = "DisplayFromStr")]
pub address: SubstateId,
Expand All @@ -61,34 +61,34 @@ pub struct InspectSubstateResponse {
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct SubmitTransactionRequest {
pub transaction: Transaction,
pub required_substates: Vec<SubstateRequirement>,
pub is_dry_run: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct SubmitTransactionResponse {
pub transaction_id: TransactionId,
pub result: IndexerTransactionFinalizedResult,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetTransactionResultRequest {
pub transaction_id: TransactionId,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetTransactionResultResponse {
pub result: IndexerTransactionFinalizedResult,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub enum IndexerTransactionFinalizedResult {
Pending,
Finalized {
Expand All @@ -103,7 +103,7 @@ pub enum IndexerTransactionFinalizedResult {
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetIdentityResponse {
pub peer_id: String,
#[cfg_attr(feature = "ts", ts(type = "string"))]
Expand All @@ -114,31 +114,31 @@ pub struct GetIdentityResponse {

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct AddAddressRequest {
#[serde_as(as = "DisplayFromStr")]
pub address: SubstateId,
}

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct DeleteAddressRequest {
#[serde_as(as = "DisplayFromStr")]
pub address: SubstateId,
}

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetNonFungibleCountRequest {
#[serde_as(as = "DisplayFromStr")]
pub address: SubstateId,
}

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetNonFungiblesRequest {
#[serde_as(as = "DisplayFromStr")]
pub address: SubstateId,
Expand All @@ -147,14 +147,14 @@ pub struct GetNonFungiblesRequest {
}

#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetNonFungiblesResponse {
pub non_fungibles: Vec<NonFungibleSubstate>,
}

#[serde_as]
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct NonFungibleSubstate {
pub index: u64,
#[serde_as(as = "DisplayFromStr")]
Expand All @@ -164,21 +164,21 @@ pub struct NonFungibleSubstate {

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetRelatedTransactionsRequest {
#[serde_as(as = "DisplayFromStr")]
pub address: SubstateId,
pub version: Option<u32>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetRelatedTransactionsResponse {
pub transaction_results: Vec<IndexerTransactionFinalizedResult>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct AddPeerRequest {
#[cfg_attr(feature = "ts", ts(type = "string"))]
pub public_key: PublicKey,
Expand All @@ -188,18 +188,18 @@ pub struct AddPeerRequest {
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct AddPeerResponse {}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetEpochManagerStatsResponse {
pub current_epoch: Epoch,
pub current_block_height: u64,
}

#[derive(Serialize, Debug)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct Connection {
pub connection_id: String,
pub peer_id: String,
Expand All @@ -213,14 +213,14 @@ pub struct Connection {
}

#[derive(Serialize, Debug)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub enum ConnectionDirection {
Inbound,
Outbound,
}

#[derive(Serialize, Debug)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/"))]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct GetConnectionsResponse {
pub connections: Vec<Connection>,
}
Loading

0 comments on commit 4baff13

Please sign in to comment.