From d408f1788a83fcad4e1db5800e65545b768ea6c2 Mon Sep 17 00:00:00 2001 From: Cifko Date: Mon, 29 Jan 2024 08:21:42 +0100 Subject: [PATCH] small update --- bindings/index.ts | 1 + bindings/src/helpers/helpers.ts | 65 +++++++++++++++++--- bindings/src/types/CallInstructionRequest.ts | 18 ++++++ bindings/src/types/Claims.ts | 2 +- bindings/src/types/LogEntry.ts | 2 +- clients/validator_node_client/src/types.rs | 1 + clients/wallet_daemon_client/src/types.rs | 4 ++ dan_layer/wallet/sdk/src/apis/jwt.rs | 1 + 8 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 bindings/src/types/CallInstructionRequest.ts diff --git a/bindings/index.ts b/bindings/index.ts index 148aed9869..7a7dba5780 100644 --- a/bindings/index.ts +++ b/bindings/index.ts @@ -38,6 +38,7 @@ 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"; export * from "./src/types/ClaimBurnResponse"; export * from "./src/types/Claims"; diff --git a/bindings/src/helpers/helpers.ts b/bindings/src/helpers/helpers.ts index ceb050de48..1f645d8b95 100644 --- a/bindings/src/helpers/helpers.ts +++ b/bindings/src/helpers/helpers.ts @@ -1,7 +1,13 @@ +import { JrpcPermission } from "../types/JrpcPermission"; import { RejectReason } from "../types/RejectReason"; +import { SubstateDiff } from "../types/SubstateDiff"; import { SubstateId } from "../types/SubstateId"; +import { TransactionResult } from "../types/TransactionResult"; -export function substateIdToString(substateId: SubstateId): string { +export function substateIdToString(substateId: SubstateId | null): string { + if (substateId === null) { + return ""; + } if ("Component" in substateId) { return substateId.Component; } @@ -30,25 +36,70 @@ export function substateIdToString(substateId: SubstateId): string { return "Unknown"; } -export function rejectReasonToString(reason: RejectReason): string { +export function rejectReasonToString(reason: RejectReason | null): string { + if (reason === null) { + return ""; + } if (typeof reason === "string") { return reason; } if ("ShardsNotPledged" in reason) { - return reason.ShardsNotPledged; + return `ShardsNotPledged(${reason.ShardsNotPledged})`; } if ("ExecutionFailure" in reason) { - return reason.ExecutionFailure; + return `ExecutionFailure(${reason.ExecutionFailure})`; } if ("ShardPledgedToAnotherPayload" in reason) { - return reason.ShardPledgedToAnotherPayload; + return `ShardPledgedToAnotherPayload(${reason.ShardPledgedToAnotherPayload})`; } if ("ShardRejected" in reason) { - return reason.ShardRejected; + return `ShardRejected(${reason.ShardRejected})`; } if ("FeesNotPaid" in reason) { - return reason.FeesNotPaid; + return `FeesNotPaid(${reason.FeesNotPaid})`; } console.error("Unknown reason", reason); return "Unknown"; } + +export function getSubstateDiffFromTransactionResult(result: TransactionResult): SubstateDiff | null { + if ("Accept" in result) { + return result.Accept; + } + if ("AcceptFeeRejectRest" in result) { + return result.AcceptFeeRejectRest[0]; + } + return null; +} + +export function getRejectReasonFromTransactionResult(result: TransactionResult): RejectReason | null { + if ("Reject" in result) { + return result.Reject; + } + if ("AcceptFeeRejectRest" in result) { + return result.AcceptFeeRejectRest[1]; + } + return null; +} + +export function jrpcPermissionToString(jrpcPermission: JrpcPermission): string { + if (typeof jrpcPermission === "string") { + return jrpcPermission; + } + if ("NftGetOwnershipProof" in jrpcPermission) { + return `NftGetOwnershipProof(${jrpcPermission.NftGetOwnershipProof})`; + } + if ("AccountBalance" in jrpcPermission) { + return `AccountBalance(${substateIdToString(jrpcPermission.AccountBalance)})`; + } + if ("AccountList" in jrpcPermission) { + return `AccountList(${jrpcPermission.AccountList})`; + } + if ("TransactionSend" in jrpcPermission) { + return `TransactionSend(${jrpcPermission.TransactionSend})`; + } + if ("GetNft" in jrpcPermission) { + return `GetNft(${substateIdToString(jrpcPermission.GetNft[0])}, ${jrpcPermission.GetNft[1]})`; + } + return "Unknown"; +} diff --git a/bindings/src/types/CallInstructionRequest.ts b/bindings/src/types/CallInstructionRequest.ts new file mode 100644 index 0000000000..efe71c2b2c --- /dev/null +++ b/bindings/src/types/CallInstructionRequest.ts @@ -0,0 +1,18 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ComponentAddressOrName } from "./ComponentAddressOrName"; +import type { Instruction } from "./Instruction"; +import type { SubstateRequirement } from "./SubstateRequirement"; + +export interface CallInstructionRequest { + instructions: Array; + fee_account: ComponentAddressOrName; + dump_outputs_into: ComponentAddressOrName | null; + max_fee: bigint; + inputs: Array; + override_inputs: boolean | null; + new_outputs: number | null; + is_dry_run: boolean; + proof_ids: Array; + min_epoch: bigint | null; + max_epoch: bigint | null; +} diff --git a/bindings/src/types/Claims.ts b/bindings/src/types/Claims.ts index 9d657815cf..03c6b98d7d 100644 --- a/bindings/src/types/Claims.ts +++ b/bindings/src/types/Claims.ts @@ -2,7 +2,7 @@ import type { JrpcPermissions } from "./JrpcPermissions"; export interface Claims { - id: bigint; + id: number; name: string; permissions: JrpcPermissions; exp: number; diff --git a/bindings/src/types/LogEntry.ts b/bindings/src/types/LogEntry.ts index fec6ce1ce2..6c253638f1 100644 --- a/bindings/src/types/LogEntry.ts +++ b/bindings/src/types/LogEntry.ts @@ -2,7 +2,7 @@ import type { LogLevel } from "./LogLevel"; export interface LogEntry { - timestamp: bigint; + timestamp: number; message: string; level: LogLevel; } diff --git a/clients/validator_node_client/src/types.rs b/clients/validator_node_client/src/types.rs index d9f7597a9d..390f133cac 100644 --- a/clients/validator_node_client/src/types.rs +++ b/clients/validator_node_client/src/types.rs @@ -248,6 +248,7 @@ pub struct GetBlocksCountResponse { #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] pub struct LogEntry { + #[cfg_attr(feature = "ts", ts(type = "number"))] pub timestamp: u64, pub message: String, pub level: LogLevel, diff --git a/clients/wallet_daemon_client/src/types.rs b/clients/wallet_daemon_client/src/types.rs index b63a5ecf86..a17f4ebdf2 100644 --- a/clients/wallet_daemon_client/src/types.rs +++ b/clients/wallet_daemon_client/src/types.rs @@ -54,12 +54,14 @@ use crate::{ }; #[derive(Debug, Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] pub struct CallInstructionRequest { pub instructions: Vec, #[serde(deserialize_with = "string_or_struct")] pub fee_account: ComponentAddressOrName, #[serde(default, deserialize_with = "opt_string_or_struct")] pub dump_outputs_into: Option, + #[cfg_attr(feature = "ts", ts(type = "number"))] pub max_fee: u64, #[serde(default)] pub inputs: Vec, @@ -72,8 +74,10 @@ pub struct CallInstructionRequest { #[serde(default)] pub proof_ids: Vec, #[serde(default)] + #[cfg_attr(feature = "ts", ts(type = "number | null"))] pub min_epoch: Option, #[serde(default)] + #[cfg_attr(feature = "ts", ts(type = "number | null"))] pub max_epoch: Option, } diff --git a/dan_layer/wallet/sdk/src/apis/jwt.rs b/dan_layer/wallet/sdk/src/apis/jwt.rs index 6f9ee893d0..75bf8aed7b 100644 --- a/dan_layer/wallet/sdk/src/apis/jwt.rs +++ b/dan_layer/wallet/sdk/src/apis/jwt.rs @@ -144,6 +144,7 @@ impl TryFrom<&[String]> for JrpcPermissions { #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] pub struct Claims { + #[cfg_attr(feature = "ts", ts(type = "number"))] pub id: u64, pub name: String, pub permissions: JrpcPermissions,