Skip to content

Commit

Permalink
Merge pull request #9 from JudeTulel/IoTBackend
Browse files Browse the repository at this point in the history
Io t backend
  • Loading branch information
JudeTulel authored Oct 11, 2024
2 parents eb235e5 + 2fc5c16 commit ebec4b0
Show file tree
Hide file tree
Showing 100 changed files with 92,527 additions and 347 deletions.
12 changes: 9 additions & 3 deletions .dfx/local/canister_ids.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"BlockThings_backend": {
"local": "bw4dl-smaaa-aaaaa-qaacq-cai"
"local": "bd3sg-teaaa-aaaaa-qaaba-cai"
},
"BlockThings_frontend": {
"local": "b77ix-eeaaa-aaaaa-qaada-cai"
"local": "be2us-64aaa-aaaaa-qaabq-cai"
},
"__Candid_UI": {
"local": "bw4dl-smaaa-aaaaa-qaacq-cai"
},
"candid_ui": {
"local": "bkyz2-fmaaa-aaaaa-qaaaq-cai"
},
"internet_identity": {
"local": "by6od-j4aaa-aaaaa-qaadq-cai"
"local": "br5f7-7uaaa-aaaaa-qaaca-cai"
}
}
52 changes: 52 additions & 0 deletions .dfx/local/canisters/BlockThings_backend/BlockThings_backend.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
type Time = int;
type ThingId = nat;
type Thing =
record {
endpoint: text;
id: ThingId;
name: text;
nonce: text;
status: Status;
};
type Status =
record {
lastSeen: Time;
online: bool;
};
type Main =
service {
getThingData: (ThingId) -> (vec DataEntry);
getThingDataInRange: (ThingId, Time, Time) -> (vec DataEntry);
getUserThings: () -> (vec Thing);
http_request: (HttpRequest) -> (HttpResponse);
init: () -> ();
markThingOnline: (ThingId) -> (bool);
registerThing: (text) -> (Thing);
removeThing: (ThingId) -> (bool);
renameThing: (ThingId, text) -> (bool);
storeThingData: (ThingId, float64) -> (bool);
};
type HttpResponse =
record {
body: blob;
headers: vec HeaderField;
status_code: nat16;
};
type HttpRequest =
record {
body: blob;
headers: vec HeaderField;
method: text;
url: text;
};
type HeaderField =
record {
text;
text;
};
type DataEntry =
record {
timestamp: Time;
value: float64;
};
service : () -> Main
40 changes: 40 additions & 0 deletions .dfx/local/canisters/BlockThings_backend/BlockThings_backend.most
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Version: 1.0.0
type DataEntry = {timestamp : Time; value : Float};
type DataStorage =
actor {
getData : shared query ThingId -> async [DataEntry];
getDataInRange : shared query (ThingId, Time, Time) -> async [DataEntry];
storeData : shared (ThingId, Float) -> async Bool
};
type DataStorage__1 = DataStorage;
type HeaderField = (Text, Text);
type HttpRequest =
{body : Blob; headers : [HeaderField]; method : Text; url : Text};
type HttpResponse =
{body : Blob; headers : [HeaderField]; status_code : Nat16};
type IoTBackend =
actor {
http_request : shared HttpRequest -> async HttpResponse;
initialize : shared (DataStorage__1, UserThings__1) -> async ()
};
type IoTBackend__1 = IoTBackend;
type Status = {lastSeen : Time; online : Bool};
type Thing =
{endpoint : Text; id : ThingId; name : Text; nonce : Text; status : Status};
type ThingId = Nat;
type Time = Int;
type UserThings =
actor {
getUserThings : shared query () -> async [Thing];
markThingOnline : shared ThingId -> async Bool;
registerThing : shared Text -> async Thing;
removeThing : shared ThingId -> async Bool;
renameThing : shared (ThingId, Text) -> async Bool;
updateThingEndpoint : shared (ThingId, Text) -> async Bool
};
type UserThings__1 = UserThings;
actor {
stable var backendActor : ?IoTBackend__1;
stable var storageActor : ?DataStorage__1;
stable var userThingsActor : ?UserThings__1
};
Binary file not shown.
36 changes: 36 additions & 0 deletions .dfx/local/canisters/BlockThings_backend/constructor.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
type DataEntry = record { value : float64; timestamp : Time };
type HeaderField = record { text; text };
type HttpRequest = record {
url : text;
method : text;
body : blob;
headers : vec HeaderField;
};
type HttpResponse = record {
body : blob;
headers : vec HeaderField;
status_code : nat16;
};
type Main = service {
getThingData : (ThingId) -> (vec DataEntry);
getThingDataInRange : (ThingId, Time, Time) -> (vec DataEntry);
getUserThings : () -> (vec Thing);
http_request : (HttpRequest) -> (HttpResponse);
init : () -> ();
markThingOnline : (ThingId) -> (bool);
registerThing : (text) -> (Thing);
removeThing : (ThingId) -> (bool);
renameThing : (ThingId, text) -> (bool);
storeThingData : (ThingId, float64) -> (bool);
};
type Status = record { lastSeen : Time; online : bool };
type Thing = record {
id : ThingId;
status : Status;
endpoint : text;
name : text;
nonce : text;
};
type ThingId = nat;
type Time = int;
service : () -> Main
42 changes: 42 additions & 0 deletions .dfx/local/canisters/BlockThings_backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Actor, HttpAgent } from "@dfinity/agent";

// Imports and re-exports candid interface
import { idlFactory } from './BlockThings_backend.did.js';
export { idlFactory } from './BlockThings_backend.did.js';
// CANISTER_ID is replaced by webpack based on node environment
export const canisterId = process.env.CANISTER_ID_BLOCKTHINGS_BACKEND;

/**
* @deprecated since dfx 0.11.1
* Do not import from `.dfx`, instead switch to using `dfx generate` to generate your JS interface.
* @param {string | import("@dfinity/principal").Principal} canisterId Canister ID of Agent
* @param {{agentOptions?: import("@dfinity/agent").HttpAgentOptions; actorOptions?: import("@dfinity/agent").ActorConfig} | { agent?: import("@dfinity/agent").Agent; actorOptions?: import("@dfinity/agent").ActorConfig }} [options]
* @return {import("@dfinity/agent").ActorSubclass<import("./BlockThings_backend.did.js")._SERVICE>}
*/
export const createActor = (canisterId, options = {}) => {
console.warn(`Deprecation warning: you are currently importing code from .dfx. Going forward, refactor to use the dfx generate command for JavaScript bindings.
See https://internetcomputer.org/docs/current/developer-docs/updates/release-notes/ for migration instructions`);
const agent = options.agent || new HttpAgent({ ...options.agentOptions });

// 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 ? options.actorOptions : {}),
});
};

/**
* A ready-to-use agent for the BlockThings_backend canister
* @type {import("@dfinity/agent").ActorSubclass<import("./BlockThings_backend.did.js")._SERVICE>}
*/
export const BlockThings_backend = createActor(canisterId);
1 change: 1 addition & 0 deletions .dfx/local/canisters/BlockThings_backend/init_args.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
()
36 changes: 36 additions & 0 deletions .dfx/local/canisters/BlockThings_backend/service.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
type DataEntry = record { value : float64; timestamp : Time };
type HeaderField = record { text; text };
type HttpRequest = record {
url : text;
method : text;
body : blob;
headers : vec HeaderField;
};
type HttpResponse = record {
body : blob;
headers : vec HeaderField;
status_code : nat16;
};
type Main = service {
getThingData : (ThingId) -> (vec DataEntry);
getThingDataInRange : (ThingId, Time, Time) -> (vec DataEntry);
getUserThings : () -> (vec Thing);
http_request : (HttpRequest) -> (HttpResponse);
init : () -> ();
markThingOnline : (ThingId) -> (bool);
registerThing : (text) -> (Thing);
removeThing : (ThingId) -> (bool);
renameThing : (ThingId, text) -> (bool);
storeThingData : (ThingId, float64) -> (bool);
};
type Status = record { lastSeen : Time; online : bool };
type Thing = record {
id : ThingId;
status : Status;
endpoint : text;
name : text;
nonce : text;
};
type ThingId = nat;
type Time = int;
service : Main
42 changes: 42 additions & 0 deletions .dfx/local/canisters/BlockThings_backend/service.did.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export interface DataEntry { 'value' : number, 'timestamp' : Time }
export type HeaderField = [string, string];
export interface HttpRequest {
'url' : string,
'method' : string,
'body' : Uint8Array | number[],
'headers' : Array<HeaderField>,
}
export interface HttpResponse {
'body' : Uint8Array | number[],
'headers' : Array<HeaderField>,
'status_code' : number,
}
export interface Main {
'getThingData' : ActorMethod<[ThingId], Array<DataEntry>>,
'getThingDataInRange' : ActorMethod<[ThingId, Time, Time], Array<DataEntry>>,
'getUserThings' : ActorMethod<[], Array<Thing>>,
'http_request' : ActorMethod<[HttpRequest], HttpResponse>,
'init' : ActorMethod<[], undefined>,
'markThingOnline' : ActorMethod<[ThingId], boolean>,
'registerThing' : ActorMethod<[string], Thing>,
'removeThing' : ActorMethod<[ThingId], boolean>,
'renameThing' : ActorMethod<[ThingId, string], boolean>,
'storeThingData' : ActorMethod<[ThingId, number], boolean>,
}
export interface Status { 'lastSeen' : Time, 'online' : boolean }
export interface Thing {
'id' : ThingId,
'status' : Status,
'endpoint' : string,
'name' : string,
'nonce' : string,
}
export type ThingId = bigint;
export type Time = bigint;
export interface _SERVICE extends Main {}
export declare const idlFactory: IDL.InterfaceFactory;
export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];
43 changes: 43 additions & 0 deletions .dfx/local/canisters/BlockThings_backend/service.did.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export const idlFactory = ({ IDL }) => {
const ThingId = IDL.Nat;
const Time = IDL.Int;
const DataEntry = IDL.Record({ 'value' : IDL.Float64, 'timestamp' : Time });
const Status = IDL.Record({ 'lastSeen' : Time, 'online' : IDL.Bool });
const Thing = IDL.Record({
'id' : ThingId,
'status' : Status,
'endpoint' : IDL.Text,
'name' : IDL.Text,
'nonce' : IDL.Text,
});
const HeaderField = IDL.Tuple(IDL.Text, IDL.Text);
const HttpRequest = IDL.Record({
'url' : IDL.Text,
'method' : IDL.Text,
'body' : IDL.Vec(IDL.Nat8),
'headers' : IDL.Vec(HeaderField),
});
const HttpResponse = IDL.Record({
'body' : IDL.Vec(IDL.Nat8),
'headers' : IDL.Vec(HeaderField),
'status_code' : IDL.Nat16,
});
const Main = IDL.Service({
'getThingData' : IDL.Func([ThingId], [IDL.Vec(DataEntry)], []),
'getThingDataInRange' : IDL.Func(
[ThingId, Time, Time],
[IDL.Vec(DataEntry)],
[],
),
'getUserThings' : IDL.Func([], [IDL.Vec(Thing)], []),
'http_request' : IDL.Func([HttpRequest], [HttpResponse], []),
'init' : IDL.Func([], [], []),
'markThingOnline' : IDL.Func([ThingId], [IDL.Bool], []),
'registerThing' : IDL.Func([IDL.Text], [Thing], []),
'removeThing' : IDL.Func([ThingId], [IDL.Bool], []),
'renameThing' : IDL.Func([ThingId, IDL.Text], [IDL.Bool], []),
'storeThingData' : IDL.Func([ThingId, IDL.Float64], [IDL.Bool], []),
});
return Main;
};
export const init = ({ IDL }) => { return []; };
36 changes: 36 additions & 0 deletions .dfx/local/lsp/bd3sg-teaaa-aaaaa-qaaba-cai.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
type DataEntry = record { value : float64; timestamp : Time };
type HeaderField = record { text; text };
type HttpRequest = record {
url : text;
method : text;
body : blob;
headers : vec HeaderField;
};
type HttpResponse = record {
body : blob;
headers : vec HeaderField;
status_code : nat16;
};
type Main = service {
getThingData : (ThingId) -> (vec DataEntry);
getThingDataInRange : (ThingId, Time, Time) -> (vec DataEntry);
getUserThings : () -> (vec Thing);
http_request : (HttpRequest) -> (HttpResponse);
init : () -> ();
markThingOnline : (ThingId) -> (bool);
registerThing : (text) -> (Thing);
removeThing : (ThingId) -> (bool);
renameThing : (ThingId, text) -> (bool);
storeThingData : (ThingId, float64) -> (bool);
};
type Status = record { lastSeen : Time; online : bool };
type Thing = record {
id : ThingId;
status : Status;
endpoint : text;
name : text;
nonce : text;
};
type ThingId = nat;
type Time = int;
service : Main
2 changes: 1 addition & 1 deletion .dfx/local/network-id
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"created": "2024-10-01 10:54:57.177217134 +00:00:00",
"created": "2024-10-11 00:35:34.506597787 +00:00:00",
"settings_digest": "48faaaab2ee980300d61ae7973164498455a339b3d386af27388cb7b0e7a2b54"
}
12 changes: 6 additions & 6 deletions .env
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

# DFX CANISTER ENVIRONMENT VARIABLES
DFX_VERSION='0.23.0'
DFX_VERSION='0.24.0'
DFX_NETWORK='local'
CANISTER_ID_BLOCKTHINGS_BACKEND='gtoqv-abflm-puhsa-apxdq'
CANISTER_ID_BLOCKTHINGS_FRONTEND='37zzu-4g5o3-zi4mg-sokcq'
CANISTER_ID_INTERNET_IDENTITY='sd32l-xcmus-z45px-vwgvq'
CANISTER_ID='gtoqv-abflm-puhsa-apxdq'
CANISTER_CANDID_PATH='/home/saray/ic_iot_server/.dfx/local/canisters/BlockThings_backend/BlockThings_backend.did'
CANISTER_ID_BLOCKTHINGS_BACKEND='bd3sg-teaaa-aaaaa-qaaba-cai'
CANISTER_ID_BLOCKTHINGS_FRONTEND='be2us-64aaa-aaaaa-qaabq-cai'
CANISTER_ID_INTERNET_IDENTITY='br5f7-7uaaa-aaaaa-qaaca-cai'
CANISTER_ID='bd3sg-teaaa-aaaaa-qaaba-cai'
CANISTER_CANDID_PATH='/home/jtulel/ic_iot_server/.dfx/local/canisters/BlockThings_backend/BlockThings_backend.did'
# END DFX CANISTER ENVIRONMENT VARIABLES
Loading

0 comments on commit ebec4b0

Please sign in to comment.