Skip to content

Commit

Permalink
Merge pull request #1447 from demergent-labs/stable_json
Browse files Browse the repository at this point in the history
refactor CandidType and Serializable
  • Loading branch information
lastmjs authored Nov 9, 2023
2 parents 619f35f + b358044 commit f27874e
Show file tree
Hide file tree
Showing 77 changed files with 243 additions and 221 deletions.
25 changes: 20 additions & 5 deletions canisters/management/bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,83 @@ import {
Vec
} from '../../src/lib';

export type BitcoinAddress = text;
export const BitcoinAddress = text;
export type BlockHash = blob;
export type BitcoinAddress = text;

export const BlockHash = blob;
export type Page = blob;
export type BlockHash = blob;

export const Page = blob;
export type MillisatoshiPerByte = nat64;
export type Page = blob;

export const MillisatoshiPerByte = nat64;
export type Satoshi = nat64;
export type MillisatoshiPerByte = nat64;

export const Satoshi = nat64;
export type Satoshi = nat64;

export const BitcoinNetwork = Variant({
Mainnet: Null,
Regtest: Null,
Testnet: Null
});
export type BitcoinNetwork = typeof BitcoinNetwork.tsType;

export const Outpoint = Record({
txid: blob,
vout: nat32
});
export type Outpoint = typeof Outpoint.tsType;

export const Utxo = Record({
height: nat32,
outpoint: Outpoint,
value: Satoshi
});
export type Utxo = typeof Utxo.tsType;

export const UtxosFilter = Variant({
MinConfirmations: nat32,
Page: Page
});
export type UtxosFilter = typeof UtxosFilter.tsType;

export const GetBalanceArgs = Record({
address: BitcoinAddress,
min_confirmations: Opt(nat32),
network: BitcoinNetwork
});
export type GetBalanceArgs = typeof GetBalanceArgs.tsType;

export const GetCurrentFeePercentilesArgs = Record({
network: BitcoinNetwork
});
export type GetCurrentFeePercentilesArgs =
typeof GetCurrentFeePercentilesArgs.tsType;

export const GetUtxosArgs = Record({
address: BitcoinAddress,
filter: Opt(UtxosFilter),
network: BitcoinNetwork
});
export type GetUtxosArgs = typeof GetUtxosArgs.tsType;

export const GetUtxosResult = Record({
next_page: Opt(Page),
tip_block_hash: BlockHash,
tip_height: nat32,
utxos: Vec(Utxo)
});
export type GetUtxosResult = typeof GetUtxosResult.tsType;

export const SendTransactionArgs = Record({
transaction: blob,
network: BitcoinNetwork
});
export type SendTransactionArgs = typeof SendTransactionArgs.tsType;

export const SendTransactionError = Variant({
MalformedTransaction: Null,
QueueFull: Null
});
export type SendTransactionError = typeof SendTransactionError.tsType;
11 changes: 11 additions & 0 deletions canisters/management/canister_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ export const CanisterInfoArgs = Record({
*/
num_requested_changes: Opt(nat64)
});
export type CanisterInfoArgs = typeof CanisterInfoArgs.tsType;

/** Details about a canister creation. */
export const CreationRecord = Record({
/** Initial set of canister controllers. */
controllers: Vec(Principal)
});
export type CreationRecord = typeof CreationRecord.tsType;

/** The mode with which a canister is installed. */
export const CanisterInstallMode = Variant({
Expand All @@ -42,6 +44,7 @@ export const CanisterInstallMode = Variant({
/** Upgrade an existing canister. */
upgrade: Null
});
export type CanisterInstallMode = typeof CanisterInstallMode.tsType;

/** Details about a canister code deployment. */
export const CodeDeploymentRecord = Record({
Expand All @@ -50,12 +53,14 @@ export const CodeDeploymentRecord = Record({
/** A SHA256 hash of the new module installed on the canister. */
module_hash: Vec(nat8)
});
export type CodeDeploymentRecord = typeof CodeDeploymentRecord.tsType;

/** Details about updating canister controllers. */
export const ControllersChangeRecord = Record({
/** The full new set of canister controllers. */
controllers: Vec(Principal)
});
export type ControllersChangeRecord = typeof ControllersChangeRecord.tsType;

/** Provides details on the respective canister change. */
export const CanisterChangeDetails = Variant({
Expand All @@ -68,12 +73,14 @@ export const CanisterChangeDetails = Variant({
/** See {@link ControllersChangeRecord}. */
controllers_change: ControllersChangeRecord
});
export type CanisterChangeDetails = typeof CanisterChangeDetails.tsType;

/** Details about a canister change initiated by a user. */
export const FromUserRecord = Record({
/** Principle of the user. */
user_id: Principal
});
export type FromUserRecord = typeof FromUserRecord.tsType;

/**
* Details about a canister change initiated by a canister (called *originator*).
Expand All @@ -89,6 +96,7 @@ export const FromCanisterRecord = Record({
*/
canister_version: Opt(nat64)
});
export type FromCanisterRecord = typeof FromCanisterRecord.tsType;

/** Provides details on who initiated a canister change. */
export const CanisterChangeOrigin = Variant({
Expand All @@ -97,6 +105,7 @@ export const CanisterChangeOrigin = Variant({
/** See {@link FromCanisterRecord}. */
from_canister: FromCanisterRecord
});
export type CanisterChangeOrigin = typeof CanisterChangeOrigin.tsType;

/** Represents a canister change as stored in the canister history. */
export const CanisterChange = Record({
Expand All @@ -112,6 +121,7 @@ export const CanisterChange = Record({
/** The change’s details. */
details: CanisterChangeDetails
});
export type CanisterChange = typeof CanisterChange.tsType;

/** Return type of {@link managementCanister.canister_info}. */
export const CanisterInfoResult = Record({
Expand All @@ -135,3 +145,4 @@ export const CanisterInfoResult = Record({
/** Controllers of the canister. */
controllers: Vec(Principal)
});
export type CanisterInfoResult = typeof CanisterInfoResult.tsType;
26 changes: 26 additions & 0 deletions canisters/management/canister_management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ import {
} from '../../src/lib';

export const CanisterId = Principal;
export type CanisterId = Principal;

export const UserId = Principal;
export type UserId = Principal;

export const WasmModule = blob;
export type WasmModule = blob;

export const CanisterSettings = Record({
/**
Expand All @@ -26,6 +31,7 @@ export const CanisterSettings = Record({
memory_allocation: Opt(nat),
freezing_threshold: Opt(nat)
});
export type CanisterSettings = typeof CanisterSettings.tsType;

/**
* The arguments to provide to the management canister's create_canister
Expand All @@ -34,23 +40,27 @@ export const CanisterSettings = Record({
export const CreateCanisterArgs = Record({
settings: Opt(CanisterSettings)
});
export type CreateCanisterArgs = typeof CreateCanisterArgs.tsType;

export const CreateCanisterResult = Record({
canister_id: Principal
});
export type CreateCanisterResult = typeof CreateCanisterResult.tsType;

export const CanisterStatus = Variant({
running: Null,
stopping: Null,
stopped: Null
});
export type CanisterStatus = typeof CanisterStatus.tsType;

export const DefiniteCanisterSettings = Record({
controllers: Vec(Principal),
compute_allocation: nat,
memory_allocation: nat,
freezing_threshold: nat
});
export type DefiniteCanisterSettings = typeof DefiniteCanisterSettings.tsType;

export const CanisterStatusResult = Record({
status: CanisterStatus,
Expand All @@ -59,59 +69,75 @@ export const CanisterStatusResult = Record({
memory_size: nat,
cycles: nat
});
export type CanisterStatusResult = typeof CanisterStatusResult.tsType;

export const CanisterStatusArgs = Record({
canister_id: Principal
});
export type CanisterStatusArgs = typeof CanisterStatusArgs.tsType;

export const UpdateSettingsArgs = Record({
canister_id: CanisterId,
settings: CanisterSettings
});
export type UpdateSettingsArgs = typeof UpdateSettingsArgs.tsType;

export const InstallCodeMode = Variant({
install: Null,
reinstall: Null,
upgrade: Null
});
export type InstallCodeMode = typeof InstallCodeMode.tsType;

export const InstallCodeArgs = Record({
mode: InstallCodeMode,
canister_id: CanisterId,
wasm_module: WasmModule,
arg: blob
});
export type InstallCodeArgs = typeof InstallCodeArgs.tsType;

export const UninstallCodeArgs = Record({
canister_id: CanisterId
});
export type UninstallCodeArgs = typeof UninstallCodeArgs.tsType;

export const StartCanisterArgs = Record({
canister_id: CanisterId
});
export type StartCanisterArgs = typeof StartCanisterArgs.tsType;

export const StopCanisterArgs = Record({
canister_id: CanisterId
});
export type StopCanisterArgs = typeof StopCanisterArgs.tsType;

export const DeleteCanisterArgs = Record({
canister_id: CanisterId
});
export type DeleteCanisterArgs = typeof DeleteCanisterArgs.tsType;

export const ProvisionalCreateCanisterWithCyclesArgs = Record({
amount: Opt(nat),
settings: Opt(CanisterSettings)
});
export type ProvisionalCreateCanisterWithCyclesArgs =
typeof ProvisionalCreateCanisterWithCyclesArgs.tsType;

export const ProvisionalCreateCanisterWithCyclesResult = Record({
canister_id: CanisterId
});
export type ProvisionalCreateCanisterWithCyclesResult =
typeof ProvisionalCreateCanisterWithCyclesResult.tsType;

export const ProvisionalTopUpCanisterArgs = Record({
canister_id: CanisterId,
amount: nat
});
export type ProvisionalTopUpCanisterArgs =
typeof ProvisionalTopUpCanisterArgs.tsType;

export const DepositCyclesArgs = Record({
canister_id: CanisterId
});
export type DepositCyclesArgs = typeof DepositCyclesArgs.tsType;
7 changes: 7 additions & 0 deletions canisters/management/http_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ export const HttpHeader = Record({
name: text,
value: text
});
export type HttpHeader = typeof HttpHeader.tsType;

export const HttpMethod = Variant({
get: Null,
head: Null,
post: Null
});
export type HttpMethod = typeof HttpMethod.tsType;

export const HttpResponse = Record({
/**
Expand All @@ -39,17 +41,20 @@ export const HttpResponse = Record({
*/
body: blob
});
export type HttpResponse = typeof HttpResponse.tsType;

export const HttpTransformArgs = Record({
response: HttpResponse,
context: blob
});
export type HttpTransformArgs = typeof HttpTransformArgs.tsType;

export const HttpTransformFunc = Func(
[HttpTransformArgs],
HttpResponse,
'query'
);
export type HttpTransformFunc = typeof HttpTransformFunc.tsType;

export const HttpTransform = Record({
/**
Expand All @@ -63,6 +68,7 @@ export const HttpTransform = Record({
*/
context: blob
});
export type HttpTransform = typeof HttpTransform.tsType;

export const HttpRequestArgs = Record({
/**
Expand Down Expand Up @@ -100,3 +106,4 @@ export const HttpRequestArgs = Record({
*/
transform: Opt(HttpTransform)
});
export type HttpRequestArgs = typeof HttpRequestArgs.tsType;
6 changes: 6 additions & 0 deletions canisters/management/t_ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,35 @@ import {
export const EcdsaCurve = Variant({
secp256k1: Null
});
export type EcdsaCurve = typeof EcdsaCurve.tsType;

export const KeyId = Record({
curve: EcdsaCurve,
name: text
});
export type KeyId = typeof KeyId.tsType;

export const EcdsaPublicKeyArgs = Record({
canister_id: Opt(Principal),
derivation_path: Vec(blob),
key_id: KeyId
});
export type EcdsaPublicKeyArgs = typeof EcdsaPublicKeyArgs.tsType;

export const EcdsaPublicKeyResult = Record({
public_key: blob,
chain_code: blob
});
export type EcdsaPublicKeyResult = typeof EcdsaPublicKeyResult.tsType;

export const SignWithEcdsaArgs = Record({
message_hash: blob,
derivation_path: Vec(blob),
key_id: KeyId
});
export type SignWithEcdsaArgs = typeof SignWithEcdsaArgs.tsType;

export const SignWithEcdsaResult = Record({
signature: blob
});
export type SignWithEcdsaResult = typeof SignWithEcdsaResult.tsType;
Loading

0 comments on commit f27874e

Please sign in to comment.