Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typescript SDK] Fix data types for transactions #1681

Merged
merged 1 commit into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 61 additions & 14 deletions sdk/typescript/src/index.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Generated type guards for "index.ts".
* WARNING: Do not manually change this file.
*/
import { Ed25519KeypairData, Keypair, PublicKeyInitData, PublicKeyData, SignedTransaction, TransactionResponse, TransferTransaction, TxnDataSerializer, TransactionDigest, SuiAddress, ObjectRef, ObjectContent, ObjectOwner, SuiObject, ObjectExistsInfo, ObjectNotExistsInfo, ObjectStatus, ObjectType, GetOwnedObjectRefsResponse, GetObjectInfoResponse, ObjectDigest, ObjectId, SequenceNumber, RawObjectRef, Transfer, RawAuthoritySignInfo, SingleTransactionKind, TransactionKind, TransactionData, Transaction, CertifiedTransaction, GatewayTxSeqNumber, GetTxnDigestsResponse, MoveModulePublish, MoveTypeTag, MoveCall, EmptySignInfo, AuthorityName, AuthoritySignature } from "./index";
import { Ed25519KeypairData, Keypair, PublicKeyInitData, PublicKeyData, SignedTransaction, TransactionResponse, TransferTransaction, TxnDataSerializer, TransactionDigest, SuiAddress, ObjectRef, ObjectContent, ObjectOwner, SuiObject, ObjectExistsInfo, ObjectNotExistsInfo, ObjectStatus, ObjectType, GetOwnedObjectRefsResponse, GetObjectInfoResponse, ObjectDigest, ObjectId, SequenceNumber, RawObjectRef, Transfer, RawAuthoritySignInfo, SingleTransactionKind, TransactionKind, TransactionData, Transaction, EpochId, CertifiedTransaction, GatewayTxSeqNumber, GetTxnDigestsResponse, MoveModulePublish, StructTag, MoveTypeTag, MoveCall, MoveCallArg, EmptySignInfo, AuthorityName, AuthoritySignature } from "./index";
import { BN } from "bn.js";

export function isEd25519KeypairData(obj: any, _argumentName?: string): obj is Ed25519KeypairData {
Expand Down Expand Up @@ -173,7 +173,8 @@ export function isObjectNotExistsInfo(obj: any, _argumentName?: string): obj is
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function")
typeof obj === "function") &&
isTransactionResponse(obj.objectId) as boolean
)
}

Expand Down Expand Up @@ -316,11 +317,18 @@ export function isTransaction(obj: any, _argumentName?: string): obj is Transact
)
}

export function isEpochId(obj: any, _argumentName?: string): obj is EpochId {
return (
typeof obj === "number"
)
}

export function isCertifiedTransaction(obj: any, _argumentName?: string): obj is CertifiedTransaction {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isSequenceNumber(obj.epoch) as boolean &&
isTransaction(obj.transaction) as boolean &&
Array.isArray(obj.signatures) &&
obj.signatures.every((e: any) =>
Expand Down Expand Up @@ -354,6 +362,21 @@ export function isMoveModulePublish(obj: any, _argumentName?: string): obj is Mo
)
}

export function isStructTag(obj: any, _argumentName?: string): obj is StructTag {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionResponse(obj.address) as boolean &&
isTransactionResponse(obj.module) as boolean &&
isTransactionResponse(obj.name) as boolean &&
Array.isArray(obj.type_args) &&
obj.type_args.every((e: any) =>
isMoveTypeTag(e) as boolean
)
)
}

export function isMoveTypeTag(obj: any, _argumentName?: string): obj is MoveTypeTag {
return (
(obj === "bool" ||
Expand All @@ -362,8 +385,17 @@ export function isMoveTypeTag(obj: any, _argumentName?: string): obj is MoveType
obj === "u128" ||
obj === "address" ||
obj === "signer" ||
obj === "vector" ||
obj === "struct")
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
Array.isArray(obj.vector) &&
obj.vector.every((e: any) =>
isMoveTypeTag(e) as boolean
) ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isStructTag(obj.struct) as boolean)
)
}

Expand All @@ -372,22 +404,37 @@ export function isMoveCall(obj: any, _argumentName?: string): obj is MoveCall {
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isRawObjectRef(obj.packages) as boolean &&
isRawObjectRef(obj.package) as boolean &&
isTransactionResponse(obj.module) as boolean &&
isTransactionResponse(obj.function) as boolean &&
Array.isArray(obj.type_arguments) &&
obj.type_arguments.every((e: any) =>
isMoveTypeTag(e) as boolean
) &&
Array.isArray(obj.object_arguments) &&
obj.object_arguments.every((e: any) =>
isRawObjectRef(e) as boolean
) &&
Array.isArray(obj.shared_object_arguments) &&
obj.shared_object_arguments.every((e: any) =>
isTransactionResponse(e) as boolean
) &&
Array.isArray(obj.pure_arguments)
Array.isArray(obj.arguments) &&
obj.arguments.every((e: any) =>
isMoveCallArg(e) as boolean
)
)
}

export function isMoveCallArg(obj: any, _argumentName?: string): obj is MoveCallArg {
return (
((obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
Array.isArray(obj.Pure) &&
obj.Pure.every((e: any) =>
isSequenceNumber(e) as boolean
) ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isRawObjectRef(obj.ImmOrOwnedObject) as boolean ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionResponse(obj.SharedObject) as boolean)
)
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/src/types/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type ObjectExistsInfo = {
};

export type ObjectNotExistsInfo = {
objectId: any;
objectId: ObjectId;
};

export type ObjectStatus = 'Exists' | 'NotExists' | 'Deleted';
Expand Down
30 changes: 22 additions & 8 deletions sdk/typescript/src/types/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { TransactionDigest } from './common';
import { RawObjectRef } from './objects';
import { SuiAddress, TransactionDigest } from './common';
import { ObjectId, RawObjectRef } from './objects';

export type Transfer = {
recipient: string;
Expand All @@ -27,7 +27,11 @@ export type Transaction = {
tx_signature: string;
};

// TODO: support u64
export type EpochId = number;

export type CertifiedTransaction = {
epoch: EpochId;
transaction: Transaction;
signatures: RawAuthoritySignInfo[];
};
Expand All @@ -40,26 +44,36 @@ export type MoveModulePublish = {
modules: any;
};

export type StructTag = {
address: SuiAddress;
module: string;
name: string;
type_args: MoveTypeTag[];
};
export type MoveTypeTag =
| 'bool'
| 'u8'
| 'u64'
| 'u128'
| 'address'
| 'signer'
| 'vector'
| 'struct';
| { vector: MoveTypeTag[] }
| { struct: StructTag };

export type MoveCall = {
packages: RawObjectRef;
package: RawObjectRef;
module: string;
function: string;
type_arguments: MoveTypeTag[];
object_arguments: RawObjectRef[];
shared_object_arguments: string[];
pure_arguments: any[];
arguments: MoveCallArg[];
};

export type MoveCallArg =
// TODO: convert to Uint8Array
| { Pure: number[] }
| { ImmOrOwnedObject: RawObjectRef }
| { SharedObject: ObjectId };

export type EmptySignInfo = object;
export type AuthorityName = string;
export type AuthoritySignature = string;
Loading