Skip to content

Commit

Permalink
frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 7, 2023
1 parent c84b94b commit 85a0a6a
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 29 deletions.
32 changes: 16 additions & 16 deletions service/wasm-utils/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/wasm-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hex = "0.4.3"
ic-cdk = "0.10.0"
serde = "1.0"
serde_bytes = "0.11"
candid = "0.9.1"
candid = "0.9.6"
ic-wasm = { version = "0.4.0", default-features = false }
sha2 = "0.10.6"

Expand Down
10 changes: 7 additions & 3 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async function createCanister(
): Promise<CanisterInfo> {
const timestamp = BigInt(Date.now()) * BigInt(1_000_000);
const nonce = await worker.pow(timestamp);
const info = await backend.getCanisterId(nonce);
const info = await backend.getCanisterId(nonce, "playground");
logger.log(`Got canister id ${info.id}`);
return {
id: info.id,
Expand Down Expand Up @@ -187,11 +187,15 @@ async function install(
mode: { [mode]: null },
canister_id: canisterId,
};
const installConfig = {
profiling,
is_whitelisted: false,
origin: "playground",
};
const new_info = await backend.installCode(
canisterInfo,
installArgs,
profiling,
false
installConfig
);
canisterInfo = new_info;
logger.log(`Code installed at canister id ${canisterInfo.id}`);
Expand Down
18 changes: 15 additions & 3 deletions src/declarations/backend/backend.did
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,22 @@ type Self =
(record {canister_id: canister_id;});
delete_canister: (record {canister_id: canister_id;}) -> ();
dump: () -> (vec CanisterInfo) query;
getCanisterId: (Nonce) -> (CanisterInfo);
getCanisterId: (Nonce, text) -> (CanisterInfo);
getInitParams: () -> (InitParams) query;
getStats: () -> (Stats) query;
getStats: () -> (Stats, vec record {
text;
nat;
}, vec record {
text;
nat;
}) query;
getSubtree: (CanisterInfo) ->
(vec record {
principal;
vec CanisterInfo;
}) query;
http_request: (HttpRequest) -> (HttpResponse) query;
installCode: (CanisterInfo, InstallArgs, bool, bool) -> (CanisterInfo);
installCode: (CanisterInfo, InstallArgs, InstallConfig) -> (CanisterInfo);
install_code:
(record {
arg: blob;
Expand Down Expand Up @@ -82,6 +88,12 @@ type Nonce =
nonce: nat;
timestamp: int;
};
type InstallConfig =
record {
is_whitelisted: bool;
origin: text;
profiling: bool;
};
type InstallArgs =
record {
arg: blob;
Expand Down
14 changes: 11 additions & 3 deletions src/declarations/backend/backend.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export interface InstallArgs {
mode: { reinstall: null } | { upgrade: null } | { install: null };
canister_id: Principal;
}
export interface InstallConfig {
origin: string;
profiling: boolean;
is_whitelisted: boolean;
}
export interface Nonce {
nonce: bigint;
timestamp: bigint;
Expand Down Expand Up @@ -56,16 +61,19 @@ export interface Self {
>;
delete_canister: ActorMethod<[{ canister_id: canister_id }], undefined>;
dump: ActorMethod<[], Array<CanisterInfo>>;
getCanisterId: ActorMethod<[Nonce], CanisterInfo>;
getCanisterId: ActorMethod<[Nonce, string], CanisterInfo>;
getInitParams: ActorMethod<[], InitParams>;
getStats: ActorMethod<[], Stats>;
getStats: ActorMethod<
[],
[Stats, Array<[string, bigint]>, Array<[string, bigint]>]
>;
getSubtree: ActorMethod<
[CanisterInfo],
Array<[Principal, Array<CanisterInfo>]>
>;
http_request: ActorMethod<[HttpRequest], HttpResponse>;
installCode: ActorMethod<
[CanisterInfo, InstallArgs, boolean, boolean],
[CanisterInfo, InstallArgs, InstallConfig],
CanisterInfo
>;
install_code: ActorMethod<
Expand Down
19 changes: 16 additions & 3 deletions src/declarations/backend/backend.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export const idlFactory = ({ IDL }) => {
}),
canister_id: IDL.Principal,
});
const InstallConfig = IDL.Record({
origin: IDL.Text,
profiling: IDL.Bool,
is_whitelisted: IDL.Bool,
});
const wasm_module = IDL.Vec(IDL.Nat8);
const Self = IDL.Service({
GCCanisters: IDL.Func([], [], ["oneway"]),
Expand Down Expand Up @@ -90,17 +95,25 @@ export const idlFactory = ({ IDL }) => {
[]
),
dump: IDL.Func([], [IDL.Vec(CanisterInfo)], ["query"]),
getCanisterId: IDL.Func([Nonce], [CanisterInfo], []),
getCanisterId: IDL.Func([Nonce, IDL.Text], [CanisterInfo], []),
getInitParams: IDL.Func([], [InitParams], ["query"]),
getStats: IDL.Func([], [Stats], ["query"]),
getStats: IDL.Func(
[],
[
Stats,
IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat)),
IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat)),
],
["query"]
),
getSubtree: IDL.Func(
[CanisterInfo],
[IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Vec(CanisterInfo)))],
["query"]
),
http_request: IDL.Func([HttpRequest], [HttpResponse], ["query"]),
installCode: IDL.Func(
[CanisterInfo, InstallArgs, IDL.Bool, IDL.Bool],
[CanisterInfo, InstallArgs, InstallConfig],
[CanisterInfo],
[]
),
Expand Down
16 changes: 16 additions & 0 deletions src/declarations/react_app/react_app.did
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ type SetAssetPropertiesArguments = record {
is_aliased: opt opt bool;
};

type ConfigurationResponse = record {
max_batches: opt nat64;
max_chunks: opt nat64;
max_bytes: opt nat64;
};

type ConfigureArguments = record {
max_batches: opt opt nat64;
max_chunks: opt opt nat64;
max_bytes: opt opt nat64;
};

type Permission = variant {
Commit;
ManagePermissions;
Expand Down Expand Up @@ -221,8 +233,12 @@ service: {
is_aliased: opt bool; } ) query;
set_asset_properties: (SetAssetPropertiesArguments) -> ();

get_configuration: () -> (ConfigurationResponse);
configure: (ConfigureArguments) -> ();

validate_grant_permission: (GrantPermission) -> (ValidationResult);
validate_revoke_permission: (RevokePermission) -> (ValidationResult);
validate_take_ownership: () -> (ValidationResult);
validate_commit_proposed_batch: (CommitProposedBatchArguments) -> (ValidationResult);
validate_configure: (ConfigureArguments) -> (ValidationResult);
}
13 changes: 13 additions & 0 deletions src/declarations/react_app/react_app.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export interface ComputeEvidenceArguments {
batch_id: BatchId;
max_iterations: [] | [number];
}
export interface ConfigurationResponse {
max_batches: [] | [bigint];
max_bytes: [] | [bigint];
max_chunks: [] | [bigint];
}
export interface ConfigureArguments {
max_batches: [] | [[] | [bigint]];
max_bytes: [] | [[] | [bigint]];
max_chunks: [] | [[] | [bigint]];
}
export interface CreateAssetArguments {
key: Key;
content_type: string;
Expand Down Expand Up @@ -118,6 +128,7 @@ export interface _SERVICE {
[ComputeEvidenceArguments],
[] | [Uint8Array | number[]]
>;
configure: ActorMethod<[ConfigureArguments], undefined>;
create_asset: ActorMethod<[CreateAssetArguments], undefined>;
create_batch: ActorMethod<[{}], { batch_id: BatchId }>;
create_chunk: ActorMethod<
Expand Down Expand Up @@ -157,6 +168,7 @@ export interface _SERVICE {
],
{ content: Uint8Array | number[] }
>;
get_configuration: ActorMethod<[], ConfigurationResponse>;
grant_permission: ActorMethod<[GrantPermission], undefined>;
http_request: ActorMethod<[HttpRequest], HttpResponse>;
http_request_streaming_callback: ActorMethod<
Expand Down Expand Up @@ -200,6 +212,7 @@ export interface _SERVICE {
[CommitProposedBatchArguments],
ValidationResult
>;
validate_configure: ActorMethod<[ConfigureArguments], ValidationResult>;
validate_grant_permission: ActorMethod<[GrantPermission], ValidationResult>;
validate_revoke_permission: ActorMethod<[RevokePermission], ValidationResult>;
validate_take_ownership: ActorMethod<[], ValidationResult>;
Expand Down
13 changes: 13 additions & 0 deletions src/declarations/react_app/react_app.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ export const idlFactory = ({ IDL }) => {
batch_id: BatchId,
max_iterations: IDL.Opt(IDL.Nat16),
});
const ConfigureArguments = IDL.Record({
max_batches: IDL.Opt(IDL.Opt(IDL.Nat64)),
max_bytes: IDL.Opt(IDL.Opt(IDL.Nat64)),
max_chunks: IDL.Opt(IDL.Opt(IDL.Nat64)),
});
const DeleteBatchArguments = IDL.Record({ batch_id: BatchId });
const ConfigurationResponse = IDL.Record({
max_batches: IDL.Opt(IDL.Nat64),
max_bytes: IDL.Opt(IDL.Nat64),
max_chunks: IDL.Opt(IDL.Nat64),
});
const Permission = IDL.Variant({
Prepare: IDL.Null,
ManagePermissions: IDL.Null,
Expand Down Expand Up @@ -121,6 +131,7 @@ export const idlFactory = ({ IDL }) => {
[IDL.Opt(IDL.Vec(IDL.Nat8))],
[]
),
configure: IDL.Func([ConfigureArguments], [], []),
create_asset: IDL.Func([CreateAssetArguments], [], []),
create_batch: IDL.Func(
[IDL.Record({})],
Expand Down Expand Up @@ -172,6 +183,7 @@ export const idlFactory = ({ IDL }) => {
[IDL.Record({ content: IDL.Vec(IDL.Nat8) })],
["query"]
),
get_configuration: IDL.Func([], [ConfigurationResponse], []),
grant_permission: IDL.Func([GrantPermission], [], []),
http_request: IDL.Func([HttpRequest], [HttpResponse], ["query"]),
http_request_streaming_callback: IDL.Func(
Expand Down Expand Up @@ -229,6 +241,7 @@ export const idlFactory = ({ IDL }) => {
[ValidationResult],
[]
),
validate_configure: IDL.Func([ConfigureArguments], [ValidationResult], []),
validate_grant_permission: IDL.Func(
[GrantPermission],
[ValidationResult],
Expand Down

0 comments on commit 85a0a6a

Please sign in to comment.