diff --git a/package.json b/package.json index 9449d33..3743ee0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@waves/ts-types", - "version": "1.0.6-beta.7", + "version": "1.0.7", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", "scripts": { diff --git a/src/common.ts b/src/common.ts new file mode 100644 index 0000000..6cf4bf7 --- /dev/null +++ b/src/common.ts @@ -0,0 +1,64 @@ +export type ExchangeTransactionOrderType = 'buy' | 'sell'; +export type Base64Script = string; +export type Base58Bytes = string; +export type Proofs = Array; +export type Long = string | number; +export type AssetDecimals = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; +export type Base64string = string; + +export const GENESIS_TYPE = 1 as 1; +export const PAYMENT_TYPE = 2 as 2; +export const ISSUE_TYPE = 3 as 3; +export const TRANSFER_TYPE = 4 as 4; +export const REISSUE_TYPE = 5 as 5; +export const BURN_TYPE = 6 as 6; +export const EXCHANGE_TYPE = 7 as 7; +export const LEASE_TYPE = 8 as 8; +export const CANCEL_LEASE_TYPE = 9 as 9; +export const ALIAS_TYPE = 10 as 10; +export const MASS_TRANSFER_TYPE = 11 as 11; +export const DATA_TYPE = 12 as 12; +export const SET_SCRIPT_TYPE = 13 as 13; +export const SPONSORSHIP_TYPE = 14 as 14; +export const SET_ASSET_SCRIPT_TYPE = 15 as 15; +export const INVOKE_SCRIPT_TYPE = 16 as 16; +export const UPDATE_ASSET_INFO_TYPE = 17 as 17; +export const INVOKE_EXPRESSION_TYPE = 18 as 18; +export const ETHEREUM = 19 as 19; + +export const INTEGER_DATA_TYPE = 'integer' as 'integer'; +export const BOOLEAN_DATA_TYPE = 'boolean' as 'boolean'; +export const STRING_DATA_TYPE = 'string' as 'string'; +export const BINARY_DATA_TYPE = 'binary' as 'binary'; + +export const TRANSACTION_TYPE = { + GENESIS: GENESIS_TYPE, + PAYMENT: PAYMENT_TYPE, + ISSUE: ISSUE_TYPE, + TRANSFER: TRANSFER_TYPE, + REISSUE: REISSUE_TYPE, + BURN: BURN_TYPE, + EXCHANGE: EXCHANGE_TYPE, + LEASE: LEASE_TYPE, + CANCEL_LEASE: CANCEL_LEASE_TYPE, + ALIAS: ALIAS_TYPE, + MASS_TRANSFER: MASS_TRANSFER_TYPE, + DATA: DATA_TYPE, + SET_SCRIPT: SET_SCRIPT_TYPE, + SPONSORSHIP: SPONSORSHIP_TYPE, + SET_ASSET_SCRIPT: SET_ASSET_SCRIPT_TYPE, + INVOKE_SCRIPT: INVOKE_SCRIPT_TYPE, + UPDATE_ASSET_INFO: UPDATE_ASSET_INFO_TYPE, + INVOKE_EXPRESSION: INVOKE_EXPRESSION_TYPE, + ETHEREUM: ETHEREUM, +}; + +export const DATA_FIELD_TYPE = { + INTEGER: INTEGER_DATA_TYPE, + BOOLEAN: BOOLEAN_DATA_TYPE, + STRING: STRING_DATA_TYPE, + BINARY: BINARY_DATA_TYPE, +}; + +export type TransactionType = typeof TRANSACTION_TYPE[keyof typeof TRANSACTION_TYPE]; +export type DataFiledType = typeof DATA_FIELD_TYPE[keyof typeof DATA_FIELD_TYPE]; diff --git a/src/exchange.ts b/src/exchange.ts new file mode 100644 index 0000000..33b92ac --- /dev/null +++ b/src/exchange.ts @@ -0,0 +1,74 @@ +import { ExchangeTransaction } from './index'; +import { ExchangeTransactionOrderType, Long } from './common'; + +export type ExchangeTransactionOrderData = { + version: number; + orderType: ExchangeTransactionOrderType; + assetPair: { + amountAsset: string | null; + priceAsset: string | null; + }; + price: LONG; + amount: LONG; + timestamp: number; + expiration: number; + matcherFee: LONG; + matcherPublicKey: string; + senderPublicKey: string; +}; + +export type WithVersion< + Target extends Record, + Version extends number +> = Target & { + version: Version; +}; + +type ExchangeOrderWithCustomFee = ExchangeTransactionOrderData & { + matcherFeeAssetId: string | null; +}; + +export type ExchangeTransactionOrderV1 = WithVersion< + ExchangeTransactionOrderData, + 1 +>; +export type ExchangeTransactionOrderV2 = WithVersion< + ExchangeTransactionOrderData, + 2 +>; +export type ExchangeTransactionOrderV3 = WithVersion< + ExchangeOrderWithCustomFee, + 3 +>; +export type ExchangeTransactionOrderV4 = WithVersion< + ExchangeOrderWithCustomFee, + 4 +>; + +export type ExchangeTransactionOrder = + | ExchangeTransactionOrderV1 + | ExchangeTransactionOrderV2 + | ExchangeTransactionOrderV3 + | ExchangeTransactionOrderV4; + +export type SignedIExchangeTransactionOrder< + ORDER extends ExchangeTransactionOrder +> = ORDER & + (ORDER extends { version: 1 } + ? { signature: string } + : { proofs: Array }); + +export type ExchangeTransactionOrderMap = { + 1: ExchangeTransactionOrderV1; + 2: ExchangeTransactionOrderV2; + 3: ExchangeTransactionOrderV3; + 4: ExchangeTransactionOrderV4; +}; + +export type ExchangeTransactionOrderByTx< + TX extends ExchangeTransaction +> = TX extends { version: 1 } + ? ExchangeTransactionOrderMap[1] + : TX extends { version: 2 } + ? ExchangeTransactionOrderMap[1 | 2 | 3] + : ExchangeTransactionOrder; diff --git a/src/index.ts b/src/index.ts index 6782fdc..848f4ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,59 +1,7 @@ export * from '../transactions'; +export * from './common'; export * from './parts'; +export * from './network'; -export const GENESIS_TYPE = 1 as 1; -export const PAYMENT_TYPE = 2 as 2; -export const ISSUE_TYPE = 3 as 3; -export const TRANSFER_TYPE = 4 as 4; -export const REISSUE_TYPE = 5 as 5; -export const BURN_TYPE = 6 as 6; -export const EXCHANGE_TYPE = 7 as 7; -export const LEASE_TYPE = 8 as 8; -export const CANCEL_LEASE_TYPE = 9 as 9; -export const ALIAS_TYPE = 10 as 10; -export const MASS_TRANSFER_TYPE = 11 as 11; -export const DATA_TYPE = 12 as 12; -export const SET_SCRIPT_TYPE = 13 as 13; -export const SPONSORSHIP_TYPE = 14 as 14; -export const SET_ASSET_SCRIPT_TYPE = 15 as 15; -export const INVOKE_SCRIPT_TYPE = 16 as 16; -export const UPDATE_ASSET_INFO_TYPE = 17 as 17; -export const INVOKE_EXPRESSION_TYPE = 18 as 18; -export const ETHEREUM = 19 as 19; - -export const INTEGER_DATA_TYPE = 'integer' as 'integer'; -export const BOOLEAN_DATA_TYPE = 'boolean' as 'boolean'; -export const STRING_DATA_TYPE = 'string' as 'string'; -export const BINARY_DATA_TYPE = 'binary' as 'binary'; - -export const TRANSACTION_TYPE = { - GENESIS: GENESIS_TYPE, - PAYMENT: PAYMENT_TYPE, - ISSUE: ISSUE_TYPE, - TRANSFER: TRANSFER_TYPE, - REISSUE: REISSUE_TYPE, - BURN: BURN_TYPE, - EXCHANGE: EXCHANGE_TYPE, - LEASE: LEASE_TYPE, - CANCEL_LEASE: CANCEL_LEASE_TYPE, - ALIAS: ALIAS_TYPE, - MASS_TRANSFER: MASS_TRANSFER_TYPE, - DATA: DATA_TYPE, - SET_SCRIPT: SET_SCRIPT_TYPE, - SPONSORSHIP: SPONSORSHIP_TYPE, - SET_ASSET_SCRIPT: SET_ASSET_SCRIPT_TYPE, - INVOKE_SCRIPT: INVOKE_SCRIPT_TYPE, - UPDATE_ASSET_INFO: UPDATE_ASSET_INFO_TYPE, - INVOKE_EXPRESSION: INVOKE_EXPRESSION_TYPE, - ETHEREUM: ETHEREUM, -}; - -export const DATA_FIELD_TYPE = { - INTEGER: INTEGER_DATA_TYPE, - BOOLEAN: BOOLEAN_DATA_TYPE, - STRING: STRING_DATA_TYPE, - BINARY: BINARY_DATA_TYPE, -}; - -export type TransactionType = typeof TRANSACTION_TYPE[keyof typeof TRANSACTION_TYPE]; -export type DataFiledType = typeof DATA_FIELD_TYPE[keyof typeof DATA_FIELD_TYPE]; +export * from './exchange'; +export * from './invoke'; diff --git a/src/invoke.ts b/src/invoke.ts new file mode 100644 index 0000000..ec13e83 --- /dev/null +++ b/src/invoke.ts @@ -0,0 +1,63 @@ +import { Base64string, Long } from './common'; + +export type InvokeScriptCall = { + function: string; + args: Array>; +}; + +export type InvokeScriptPayment = { + assetId: string | null; + amount: LONG; +}; + +export type InvokeScriptCallArgument = + | InvokeScriptCallStringArgument + | InvokeScriptCallBinaryArgument + | InvokeScriptCallBooleanArgument + | InvokeScriptCallIntegerArgument + | InvokeScriptCallUnionArgument + | InvokeScriptCallListArgument< + LONG, + | InvokeScriptCallStringArgument + | InvokeScriptCallBinaryArgument + | InvokeScriptCallBooleanArgument + | InvokeScriptCallIntegerArgument + >; + +export type InvokeScriptCallArgumentGeneric = { + type: Type; + value: Value; +}; + +export type InvokeScriptCallStringArgument = InvokeScriptCallArgumentGeneric< + 'string', + string +>; +export type InvokeScriptCallBinaryArgument = InvokeScriptCallArgumentGeneric< + 'binary', + Base64string +>; +export type InvokeScriptCallBooleanArgument = InvokeScriptCallArgumentGeneric< + 'boolean', + boolean +>; +export type InvokeScriptCallIntegerArgument< + LONG = Long +> = InvokeScriptCallArgumentGeneric<'integer', LONG>; +export type InvokeScriptCallUnionArgument< + LONG = Long +> = InvokeScriptCallArgumentGeneric< + 'union', + LONG | string | Base64string | boolean +> & { + valueType: 'binary' | 'boolean' | 'integer' | 'string'; +}; +export type InvokeScriptCallListArgument< + LONG, + ITEMS extends + | InvokeScriptCallStringArgument + | InvokeScriptCallBinaryArgument + | InvokeScriptCallBooleanArgument + | InvokeScriptCallIntegerArgument + | InvokeScriptCallUnionArgument +> = InvokeScriptCallArgumentGeneric<'list', Array>; diff --git a/src/network.ts b/src/network.ts new file mode 100644 index 0000000..4764096 --- /dev/null +++ b/src/network.ts @@ -0,0 +1,6 @@ +export enum ChainId { + MAINNET = 87, + STAGENET = 83, + TESTNET = 84, + PRIVATE = 80, +} diff --git a/src/parts.ts b/src/parts.ts index 15fc6b3..73e51bb 100644 --- a/src/parts.ts +++ b/src/parts.ts @@ -1,75 +1,16 @@ -import { DATA_FIELD_TYPE, ExchangeTransaction } from './index'; +import { DATA_FIELD_TYPE } from './index'; +import { AssetDecimals, Long, Base64string } from './common'; +import { InvokeScriptPayment } from './invoke'; -export type ExchangeTransactionOrderType = 'buy' | 'sell'; -export type Base64Script = string; -export type Base58Bytes = string; -export type Proofs = Array; -export type Long = string | number; -export type AssetDecimals = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; -export type Base64string = string; +export interface WithId { + id: string; +} export type WithApiMixin = WithId & { sender: string; height: number; }; -export type InvokeScriptCall = { - function: string; - args: Array>; -}; - -export type InvokeScriptPayment = { - assetId: string | null; - amount: LONG; -}; - -export type InvokeScriptCallArgument = - | InvokeScriptCallStringArgument - | InvokeScriptCallBinaryArgument - | InvokeScriptCallBooleanArgument - | InvokeScriptCallIntegerArgument - | InvokeScriptCallListArgument< - LONG, - | InvokeScriptCallStringArgument - | InvokeScriptCallBinaryArgument - | InvokeScriptCallBooleanArgument - | InvokeScriptCallIntegerArgument - >; - -export type InvokeScriptCallArgumentGeneric = { - type: Type; - value: Value; -}; - -export type InvokeScriptCallStringArgument = InvokeScriptCallArgumentGeneric< - 'string', - string ->; -export type InvokeScriptCallBinaryArgument = InvokeScriptCallArgumentGeneric< - 'binary', - Base64string ->; -export type InvokeScriptCallBooleanArgument = InvokeScriptCallArgumentGeneric< - 'boolean', - boolean ->; -export type InvokeScriptCallIntegerArgument< - LONG = Long -> = InvokeScriptCallArgumentGeneric<'integer', LONG>; - -export type InvokeScriptCallListArgument< - LONG, - ITEMS extends - | InvokeScriptCallStringArgument - | InvokeScriptCallBinaryArgument - | InvokeScriptCallBooleanArgument - | InvokeScriptCallIntegerArgument -> = InvokeScriptCallArgumentGeneric<'list', Array>; - -export interface WithId { - id: string; -} - export type MassTransferItem = { recipient: string; amount: LONG; @@ -98,78 +39,6 @@ export type DataTransactionEntryBoolean = DataTransactionEntryGeneric< boolean >; -export type ExchangeTransactionOrderData = { - version: number; - orderType: ExchangeTransactionOrderType; - assetPair: { - amountAsset: string | null; - priceAsset: string | null; - }; - price: LONG; - amount: LONG; - timestamp: number; - expiration: number; - matcherFee: LONG; - matcherPublicKey: string; - senderPublicKey: string; -}; - -export type WithVersion< - Target extends Record, - Version extends number -> = Target & { - version: Version; -}; - -type ExchangeOrderWithCustomFee = ExchangeTransactionOrderData & { - matcherFeeAssetId: string | null; -}; - -export type ExchangeTransactionOrderV1 = WithVersion< - ExchangeTransactionOrderData, - 1 ->; -export type ExchangeTransactionOrderV2 = WithVersion< - ExchangeTransactionOrderData, - 2 ->; -export type ExchangeTransactionOrderV3 = WithVersion< - ExchangeOrderWithCustomFee, - 3 ->; -export type ExchangeTransactionOrderV4 = WithVersion< - ExchangeOrderWithCustomFee, - 4 ->; - -export type ExchangeTransactionOrder = - | ExchangeTransactionOrderV1 - | ExchangeTransactionOrderV2 - | ExchangeTransactionOrderV3 - | ExchangeTransactionOrderV4; - -export type SignedIExchangeTransactionOrder< - ORDER extends ExchangeTransactionOrder -> = ORDER & - (ORDER extends { version: 1 } - ? { signature: string } - : { proofs: Array }); - -export type ExchangeTransactionOrderMap = { - 1: ExchangeTransactionOrderV1; - 2: ExchangeTransactionOrderV2; - 3: ExchangeTransactionOrderV3; - 4: ExchangeTransactionOrderV4; -}; - -export type ExchangeTransactionOrderByTx< - TX extends ExchangeTransaction -> = TX extends { version: 1 } - ? ExchangeTransactionOrderMap[1] - : TX extends { version: 2 } - ? ExchangeTransactionOrderMap[1 | 2 | 3] - : ExchangeTransactionOrder; - export type DataTransactionEntry = | DataTransactionEntryInteger | DataTransactionEntryString