Skip to content

Commit

Permalink
small update
Browse files Browse the repository at this point in the history
  • Loading branch information
Cifko committed Jan 29, 2024
1 parent 4baff13 commit d408f17
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 9 deletions.
1 change: 1 addition & 0 deletions bindings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
65 changes: 58 additions & 7 deletions bindings/src/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down Expand Up @@ -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";
}
18 changes: 18 additions & 0 deletions bindings/src/types/CallInstructionRequest.ts
Original file line number Diff line number Diff line change
@@ -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<Instruction>;
fee_account: ComponentAddressOrName;
dump_outputs_into: ComponentAddressOrName | null;
max_fee: bigint;
inputs: Array<SubstateRequirement>;
override_inputs: boolean | null;
new_outputs: number | null;
is_dry_run: boolean;
proof_ids: Array<bigint>;
min_epoch: bigint | null;
max_epoch: bigint | null;
}
2 changes: 1 addition & 1 deletion bindings/src/types/Claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { JrpcPermissions } from "./JrpcPermissions";

export interface Claims {
id: bigint;
id: number;
name: string;
permissions: JrpcPermissions;
exp: number;
Expand Down
2 changes: 1 addition & 1 deletion bindings/src/types/LogEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { LogLevel } from "./LogLevel";

export interface LogEntry {
timestamp: bigint;
timestamp: number;
message: string;
level: LogLevel;
}
1 change: 1 addition & 0 deletions clients/validator_node_client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions clients/wallet_daemon_client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Instruction>,
#[serde(deserialize_with = "string_or_struct")]
pub fee_account: ComponentAddressOrName,
#[serde(default, deserialize_with = "opt_string_or_struct")]
pub dump_outputs_into: Option<ComponentAddressOrName>,
#[cfg_attr(feature = "ts", ts(type = "number"))]
pub max_fee: u64,
#[serde(default)]
pub inputs: Vec<SubstateRequirement>,
Expand All @@ -72,8 +74,10 @@ pub struct CallInstructionRequest {
#[serde(default)]
pub proof_ids: Vec<ConfidentialProofId>,
#[serde(default)]
#[cfg_attr(feature = "ts", ts(type = "number | null"))]
pub min_epoch: Option<u64>,
#[serde(default)]
#[cfg_attr(feature = "ts", ts(type = "number | null"))]
pub max_epoch: Option<u64>,
}

Expand Down
1 change: 1 addition & 0 deletions dan_layer/wallet/sdk/src/apis/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d408f17

Please sign in to comment.