generated from veeso-dev/rust-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,250 additions
and
142 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.