Skip to content

Commit

Permalink
feat: ekoke-index canister
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Feb 20, 2024
1 parent 8e34fbc commit 5b65e8c
Show file tree
Hide file tree
Showing 29 changed files with 1,250 additions and 142 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"src/did",
"src/dip721",
"src/deferred",
"src/ekoke_index",
"src/ekoke_ledger",
"src/icrc",
"src/marketplace",
Expand Down
8 changes: 7 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ args = ["fmt", "--all", "--", "--check"]
description = "Generate did files"
dependencies = [
"deferred-did",
"ekoke-index-did",
"ekoke-ledger-did",
"marketplace-did",
"dfx-generate",
Expand All @@ -65,6 +66,11 @@ description = "Generate did files for deferred"
script = "cargo run --bin deferred-did --features did > src/deferred/deferred.did"
workspace = false

[tasks.ekoke-index-did]
description = "Generate did files for ekoke-index"
script = "cargo run --bin ekoke-index-did --features did > src/ekoke_index/ekoke-index.did"
workspace = false

[tasks.ekoke-ledger-did]
description = "Generate did files for ekoke-ledger"
script = "cargo run --bin ekoke-ledger-did --features did > src/ekoke_ledger/ekoke-ledger.did"
Expand All @@ -83,5 +89,5 @@ workspace = false

[tasks.dfx-setup]
description = "setup dfx"
script = "dfx stop; dfx start --background; dfx canister create deferred; dfx canister create ekoke-ledger; dfx canister create marketplace"
script = "./scripts/dfx-setup.sh"
workspace = false
5 changes: 5 additions & 0 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"package": "deferred",
"type": "rust"
},
"ekoke-index": {
"candid": "src/ekoke_index/ekoke-index.did",
"package": "ekoke_index",
"type": "rust"
},
"ekoke-ledger": {
"candid": "src/ekoke_ledger/ekoke-ledger.did",
"package": "ekoke_ledger",
Expand Down
10 changes: 10 additions & 0 deletions scripts/dfx-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

dfx stop
dfx start --background
dfx canister create deferred
dfx canister create ekoke-index
dfx canister create ekoke-ledger
dfx canister create marketplace

dfx stop
80 changes: 80 additions & 0 deletions src/declarations/ekoke-index/ekoke-index.did.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export interface Account {
'owner' : Principal,
'subaccount' : [] | [Uint8Array | number[]],
}
export interface Approve {
'fee' : [] | [bigint],
'from' : Account,
'memo' : [] | [Uint8Array | number[]],
'created_at_time' : [] | [bigint],
'amount' : bigint,
'expected_allowance' : [] | [bigint],
'expires_at' : [] | [bigint],
'spender' : [] | [Account],
}
export interface Burn {
'from' : Account,
'memo' : [] | [Uint8Array | number[]],
'created_at_time' : [] | [bigint],
'amount' : bigint,
'spender' : [] | [Account],
}
export interface EkokeIndexInitData { 'ledger_id' : Principal }
export interface GetAccountTransactionArgs {
'max_results' : bigint,
'start' : [] | [bigint],
'account' : Account,
}
export interface GetTransactions {
'transactions' : Array<TransactionWithId>,
'oldest_tx_id' : [] | [bigint],
}
export interface GetTransactionsErr { 'message' : string }
export interface ListSubaccountsArgs {
'owner' : Principal,
'start' : [] | [Uint8Array | number[]],
}
export interface Mint {
'to' : Account,
'memo' : [] | [Uint8Array | number[]],
'created_at_time' : [] | [bigint],
'amount' : bigint,
}
export type Result = { 'Ok' : GetTransactions } |
{ 'Err' : GetTransactionsErr };
export interface Transaction {
'burn' : [] | [Burn],
'kind' : string,
'mint' : [] | [Mint],
'approve' : [] | [Approve],
'timestamp' : bigint,
'transfer' : [] | [Transfer],
}
export interface TransactionWithId {
'id' : bigint,
'transaction' : Transaction,
}
export interface Transfer {
'to' : Account,
'fee' : [] | [bigint],
'from' : Account,
'memo' : [] | [Uint8Array | number[]],
'created_at_time' : [] | [bigint],
'amount' : bigint,
'spender' : [] | [Account],
}
export interface _SERVICE {
'commit' : ActorMethod<[Transaction], bigint>,
'get_account_transactions' : ActorMethod<[GetAccountTransactionArgs], Result>,
'ledger_id' : ActorMethod<[], Principal>,
'list_subaccounts' : ActorMethod<
[ListSubaccountsArgs],
Array<Uint8Array | number[]>
>,
}
export declare const idlFactory: IDL.InterfaceFactory;
export declare const init: ({ IDL }: { IDL: IDL }) => IDL.Type[];
87 changes: 87 additions & 0 deletions src/declarations/ekoke-index/ekoke-index.did.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
export const idlFactory = ({ IDL }) => {
const EkokeIndexInitData = IDL.Record({ 'ledger_id' : IDL.Principal });
const Account = IDL.Record({
'owner' : IDL.Principal,
'subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)),
});
const Burn = IDL.Record({
'from' : Account,
'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)),
'created_at_time' : IDL.Opt(IDL.Nat64),
'amount' : IDL.Nat,
'spender' : IDL.Opt(Account),
});
const Mint = IDL.Record({
'to' : Account,
'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)),
'created_at_time' : IDL.Opt(IDL.Nat64),
'amount' : IDL.Nat,
});
const Approve = IDL.Record({
'fee' : IDL.Opt(IDL.Nat),
'from' : Account,
'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)),
'created_at_time' : IDL.Opt(IDL.Nat64),
'amount' : IDL.Nat,
'expected_allowance' : IDL.Opt(IDL.Nat),
'expires_at' : IDL.Opt(IDL.Nat64),
'spender' : IDL.Opt(Account),
});
const Transfer = IDL.Record({
'to' : Account,
'fee' : IDL.Opt(IDL.Nat),
'from' : Account,
'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)),
'created_at_time' : IDL.Opt(IDL.Nat64),
'amount' : IDL.Nat,
'spender' : IDL.Opt(Account),
});
const Transaction = IDL.Record({
'burn' : IDL.Opt(Burn),
'kind' : IDL.Text,
'mint' : IDL.Opt(Mint),
'approve' : IDL.Opt(Approve),
'timestamp' : IDL.Nat64,
'transfer' : IDL.Opt(Transfer),
});
const GetAccountTransactionArgs = IDL.Record({
'max_results' : IDL.Nat,
'start' : IDL.Opt(IDL.Nat),
'account' : Account,
});
const TransactionWithId = IDL.Record({
'id' : IDL.Nat,
'transaction' : Transaction,
});
const GetTransactions = IDL.Record({
'transactions' : IDL.Vec(TransactionWithId),
'oldest_tx_id' : IDL.Opt(IDL.Nat),
});
const GetTransactionsErr = IDL.Record({ 'message' : IDL.Text });
const Result = IDL.Variant({
'Ok' : GetTransactions,
'Err' : GetTransactionsErr,
});
const ListSubaccountsArgs = IDL.Record({
'owner' : IDL.Principal,
'start' : IDL.Opt(IDL.Vec(IDL.Nat8)),
});
return IDL.Service({
'commit' : IDL.Func([Transaction], [IDL.Nat], []),
'get_account_transactions' : IDL.Func(
[GetAccountTransactionArgs],
[Result],
[],
),
'ledger_id' : IDL.Func([], [IDL.Principal], ['query']),
'list_subaccounts' : IDL.Func(
[ListSubaccountsArgs],
[IDL.Vec(IDL.Vec(IDL.Nat8))],
['query'],
),
});
};
export const init = ({ IDL }) => {
const EkokeIndexInitData = IDL.Record({ 'ledger_id' : IDL.Principal });
return [EkokeIndexInitData];
};
50 changes: 50 additions & 0 deletions src/declarations/ekoke-index/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type {
ActorSubclass,
HttpAgentOptions,
ActorConfig,
Agent,
} from "@dfinity/agent";
import type { Principal } from "@dfinity/principal";
import type { IDL } from "@dfinity/candid";

import { _SERVICE } from './ekoke-index.did';

export declare const idlFactory: IDL.InterfaceFactory;
export declare const canisterId: string;

export declare interface CreateActorOptions {
/**
* @see {@link Agent}
*/
agent?: Agent;
/**
* @see {@link HttpAgentOptions}
*/
agentOptions?: HttpAgentOptions;
/**
* @see {@link ActorConfig}
*/
actorOptions?: ActorConfig;
}

/**
* Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister.
* @constructs {@link ActorSubClass}
* @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to
* @param {CreateActorOptions} options - see {@link CreateActorOptions}
* @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions
* @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent
* @see {@link HttpAgentOptions}
* @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor
* @see {@link ActorConfig}
*/
export declare const createActor: (
canisterId: string | Principal,
options?: CreateActorOptions
) => ActorSubclass<_SERVICE>;

/**
* Intialized Actor using default settings, ready to talk to a canister using its candid interface
* @constructs {@link ActorSubClass}
*/
export declare const ekoke-index: ActorSubclass<_SERVICE>;
43 changes: 43 additions & 0 deletions src/declarations/ekoke-index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Actor, HttpAgent } from "@dfinity/agent";

// Imports and re-exports candid interface
import { idlFactory } from "./ekoke-index.did.js";
export { idlFactory } from "./ekoke-index.did.js";

/* CANISTER_ID is replaced by webpack based on node environment
* Note: canister environment variable will be standardized as
* process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
* beginning in dfx 0.15.0
*/
export const canisterId =
process.env.CANISTER_ID_EKOKE-INDEX ||
process.env.EKOKE-INDEX_CANISTER_ID;

export const createActor = (canisterId, options = {}) => {
const agent = options.agent || new HttpAgent({ ...options.agentOptions });

if (options.agent && options.agentOptions) {
console.warn(
"Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent."
);
}

// Fetch root key for certificate validation during development
if (process.env.DFX_NETWORK !== "ic") {
agent.fetchRootKey().catch((err) => {
console.warn(
"Unable to fetch root key. Check to ensure that your local replica is running"
);
console.error(err);
});
}

// Creates an actor with using the candid interface and the HttpAgent
return Actor.createActor(idlFactory, {
agent,
canisterId,
...options.actorOptions,
});
};

export const ekoke-index = canisterId ? createActor(canisterId) : undefined;
Loading

0 comments on commit 5b65e8c

Please sign in to comment.