Skip to content

Commit 5b570f3

Browse files
authored
Merge pull request #7 from Bebb-Protocol-and-Apps/new-entity-types
New entity types
2 parents 2a1730c + b763d1a commit 5b570f3

File tree

11 files changed

+230
-166
lines changed

11 files changed

+230
-166
lines changed

CanisterCommands.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
dfx canister call newwave create_entity "(record { _internalId = null; _creator = null; _entityType = variant {Webasset}; })"
2+
dfx canister call newwave get_entity '("D6C65674-91BE-170D-BCC0-000000000000")'
3+
dfx canister call newwave create_bridge '(record { _internalId = null; _creator = null; _entityType = variant {Webasset}; _bridgeType = variant {OwnerCreated}; _fromEntityId = "20621F98-91B0-170D-B0F5-000000000000"; _toEntityId = "D6C65674-91BE-170D-BCC0-000000000000"; })'
4+
dfx canister call newwave get_bridge '("76CBDF90-9246-170D-9C79-000000000000")'
5+
dfx canister call newwave get_bridge_ids_by_entity_id '("D6C65674-91BE-170D-BCC0-000000000000", true, true, true)'
6+
dfx canister call newwave get_bridges_by_entity_id '("D6C65674-91BE-170D-BCC0-000000000000", true, true, true)'
7+
dfx canister call newwave create_entity_and_bridge '(record { _internalId = null; _creator = null; _entityType = variant {Webasset}; }, record { _internalId = null; _creator = null; _entityType = variant {Webasset}; _bridgeType = variant {OwnerCreated}; _fromEntityId = "20621F98-91B0-170D-B0F5-000000000000"; _toEntityId = "D6C65674-91BE-170D-BCC0-000000000000"; })'
8+
dfx canister call newwave get_bridged_entities_by_entity_id '("D6C65674-91BE-170D-BCC0-000000000000", true, true, true)'
9+
dfx canister call newwave get_entity_and_bridge_ids '("D6C65674-91BE-170D-BCC0-000000000000", true, true, true)'
10+
11+
Call from CLI (IC):
12+
first deploy to IC mainnet: dfx deploy --network ic
13+
dfx canister --network ic call newwave create_entity "(record { _internalId = null; _creator = null; _entityType = variant {Webasset}; })"
14+
dfx canister --network ic call newwave get_entity '("C923CD99-92E1-170D-908C-000000000000")'
15+
## Call from CLI (local):
16+
17+
dfx canister --network ic call newwave create_bridge '(record { _internalId = null; _creator = null; _entityType = variant {Webasset}; _bridgeType = variant {OwnerCreated}; _fromEntityId = "01A90437-92F8-170D-9F6C-000000000000"; _toEntityId = "C923CD99-92E1-170D-908C-000000000000"; })'
18+
dfx canister --network ic call newwave get_bridge '("E64582AA-9302-170D-A43D-000000000000")'
19+
dfx canister --network ic call newwave get_bridge_ids_by_entity_id '("C923CD99-92E1-170D-908C-000000000000", true, true, true)'
20+
dfx canister --network ic call newwave get_bridges_by_entity_id '("C923CD99-92E1-170D-908C-000000000000", true, true, true)'
21+
dfx canister --network ic call newwave create_entity_and_bridge '(record { _internalId = null; _creator = null; _entityType = variant {Person}; }, record { _internalId = null; _creator = null; _entityType = variant {Webasset}; _bridgeType = variant {OwnerCreated}; _fromEntityId = "C923CD99-92E1-170D-908C-000000000000"; _toEntityId = ""; })'
22+
dfx canister --network ic call newwave get_bridged_entities_by_entity_id '("C923CD99-92E1-170D-908C-000000000000", true, true, true)'
23+
dfx canister --network ic call newwave get_entity_and_bridge_ids '("C923CD99-92E1-170D-908C-000000000000", true, true, true)'
24+
25+
Top up cycles:
26+
dfx identity --network=ic get-wallet
27+
dfx wallet --network ic balance
28+
dfx canister --network ic status newwave
29+
dfx canister --network ic --wallet 3v5vy-2aaaa-aaaai-aapla-cai deposit-cycles 3000000000000 newwave
30+
31+
2022-11-15: topped up 3.3T cycles, has balance of 7.2T (2023-02-20: basically hasn't changed, 2023-07-05: 7.186)
32+
33+
Fund wallet with cycles (from ICP): https://medium.com/dfinity/internet-computer-basics-part-3-funding-a-cycles-wallet-a724efebd111

DevNotes.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Dev notes
2+
dynamically expand storage canisters: https://github.com/dfinity/examples/tree/master/motoko/classes
3+
work with subaccounts: https://github.com/krpeacock/invoice-canister
4+
5+
using Entity type cuts other fields from entities -> flexible input and output format needed
6+
with Text? like stringifying object and parsing Text to object of entity type
7+
https://forum.dfinity.org/t/how-do-i-send-a-blob-from-js-frontend-to-motoko-backend/9148/2
8+
https://itnext.io/typescript-utilities-for-candid-bf5bdd92a9a3
9+
https://github.com/dfinity/motoko-base/blob/master/src/Blob.mo
10+
with HashMap? instead of object type use HashMap input and convert key-value pairs to entity type
11+
https://github.com/dfinity/motoko-base/blob/master/src/HashMap.mo
12+
having HashMap<Text,Text> as a field on Entity gives error: is or contains non-shared type Text -> ()
13+
function on Entity to retrieve entityType specific fields (or a static field)
14+
work with JSON: https://github.com/Toniq-Labs/creator-nfts/blob/main/canisters/nft/main.mo
15+
UI sends in JSON encoded as Blob: https://github.com/Toniq-Labs/creator-nfts/blob/main/frontend/src/canisters/nft/minting.ts
16+
potentially String / Text also works (i.e. no en-/decoding) --> work with Text for now, probably change to Blob later (after finding out about its potential benefits)

README.md

Lines changed: 23 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Bebb Protocol v0.0.4
2-
1+
# Bebb Protocol
32
A decentralized protocol to store and manage a form of hyperlinks between all different kinds of nodes.
43

54
This protocol, which enables everyone to create and retrieve connections, build applications on top of it and together establish a wide-spanning network of connections between different kinds of nodes, will serve as a fundamental building block of proof-of-concept applications building on top (e.g. Personal NFT Gallery).
@@ -20,9 +19,29 @@ dfx start --background
2019
dfx deploy
2120
```
2221

23-
Once the job completes, your application will be available at `http://localhost:8000?canisterId={asset_canister_id}`.
22+
## Different Stages
23+
Local:
24+
dfx deploy
25+
26+
Development:
27+
dfx deploy --network development
2428

25-
Additionally, if you are making frontend changes, you can start a development server with
29+
Testing:
30+
dfx deploy --network testing
31+
32+
Production:
33+
dfx deploy --network ic
34+
35+
## Testing Backend Changes
36+
The majority of the changes are tested via the candid backend. To access the Candid backend, after you run
37+
```bash
38+
dfx deploy
39+
```
40+
as shown above. It will provide the URL to the canister backend Candid UI. You can test the API calls through that interface
41+
42+
## Testing Frontend Changes
43+
44+
If you are making frontend changes, you can start a development server with
2645

2746
```bash
2847
npm start
@@ -31,79 +50,3 @@ npm start
3150
Which will start a server at `http://localhost:8080`, proxying API requests to the replica at port 8000.
3251

3352
Note: while the protocol doesn't need or have a UI, the asset's canister here serves as a simple way of testing the protocol by simulating how an application might create Entities and connect them via Bridges.
34-
35-
Call from CLI (local):
36-
dfx canister call newwave create_entity "(record { _internalId = null; _creator = null; _entityType = variant {Webasset}; })"
37-
dfx canister call newwave get_entity '("D6C65674-91BE-170D-BCC0-000000000000")'
38-
dfx canister call newwave create_bridge '(record { _internalId = null; _creator = null; _entityType = variant {Webasset}; _bridgeType = variant {OwnerCreated}; _fromEntityId = "20621F98-91B0-170D-B0F5-000000000000"; _toEntityId = "D6C65674-91BE-170D-BCC0-000000000000"; })'
39-
dfx canister call newwave get_bridge '("76CBDF90-9246-170D-9C79-000000000000")'
40-
dfx canister call newwave get_bridge_ids_by_entity_id '("D6C65674-91BE-170D-BCC0-000000000000", true, true, true)'
41-
dfx canister call newwave get_bridges_by_entity_id '("D6C65674-91BE-170D-BCC0-000000000000", true, true, true)'
42-
dfx canister call newwave create_entity_and_bridge '(record { _internalId = null; _creator = null; _entityType = variant {Webasset}; }, record { _internalId = null; _creator = null; _entityType = variant {Webasset}; _bridgeType = variant {OwnerCreated}; _fromEntityId = "20621F98-91B0-170D-B0F5-000000000000"; _toEntityId = "D6C65674-91BE-170D-BCC0-000000000000"; })'
43-
dfx canister call newwave get_bridged_entities_by_entity_id '("D6C65674-91BE-170D-BCC0-000000000000", true, true, true)'
44-
dfx canister call newwave get_entity_and_bridge_ids '("D6C65674-91BE-170D-BCC0-000000000000", true, true, true)'
45-
46-
Call from CLI (IC):
47-
first deploy to IC mainnet: dfx deploy --network ic
48-
dfx canister --network ic call newwave create_entity "(record { _internalId = null; _creator = null; _entityType = variant {Webasset}; })"
49-
dfx canister --network ic call newwave get_entity '("C923CD99-92E1-170D-908C-000000000000")'
50-
dfx canister --network ic call newwave create_bridge '(record { _internalId = null; _creator = null; _entityType = variant {Webasset}; _bridgeType = variant {OwnerCreated}; _fromEntityId = "01A90437-92F8-170D-9F6C-000000000000"; _toEntityId = "C923CD99-92E1-170D-908C-000000000000"; })'
51-
dfx canister --network ic call newwave get_bridge '("E64582AA-9302-170D-A43D-000000000000")'
52-
dfx canister --network ic call newwave get_bridge_ids_by_entity_id '("C923CD99-92E1-170D-908C-000000000000", true, true, true)'
53-
dfx canister --network ic call newwave get_bridges_by_entity_id '("C923CD99-92E1-170D-908C-000000000000", true, true, true)'
54-
dfx canister --network ic call newwave create_entity_and_bridge '(record { _internalId = null; _creator = null; _entityType = variant {Person}; }, record { _internalId = null; _creator = null; _entityType = variant {Webasset}; _bridgeType = variant {OwnerCreated}; _fromEntityId = "C923CD99-92E1-170D-908C-000000000000"; _toEntityId = ""; })'
55-
dfx canister --network ic call newwave get_bridged_entities_by_entity_id '("C923CD99-92E1-170D-908C-000000000000", true, true, true)'
56-
dfx canister --network ic call newwave get_entity_and_bridge_ids '("C923CD99-92E1-170D-908C-000000000000", true, true, true)'
57-
58-
Top up cycles:
59-
dfx identity --network=ic get-wallet
60-
dfx wallet --network ic balance
61-
dfx canister --network ic status newwave
62-
dfx canister --network ic --wallet 3v5vy-2aaaa-aaaai-aapla-cai deposit-cycles 3000000000000 newwave
63-
64-
2022-11-15: topped up 3.3T cycles, has balance of 7.2T (2023-02-20: basically hasn't changed, 2023-07-05: 7.186)
65-
66-
Fund wallet with cycles (from ICP): https://medium.com/dfinity/internet-computer-basics-part-3-funding-a-cycles-wallet-a724efebd111
67-
68-
## Dev notes
69-
70-
dynamically expand storage canisters: https://github.com/dfinity/examples/tree/master/motoko/classes
71-
work with subaccounts: https://github.com/krpeacock/invoice-canister
72-
73-
using Entity type cuts other fields from entities -> flexible input and output format needed
74-
with Text? like stringifying object and parsing Text to object of entity type
75-
https://forum.dfinity.org/t/how-do-i-send-a-blob-from-js-frontend-to-motoko-backend/9148/2
76-
https://itnext.io/typescript-utilities-for-candid-bf5bdd92a9a3
77-
https://github.com/dfinity/motoko-base/blob/master/src/Blob.mo
78-
with HashMap? instead of object type use HashMap input and convert key-value pairs to entity type
79-
https://github.com/dfinity/motoko-base/blob/master/src/HashMap.mo
80-
having HashMap<Text,Text> as a field on Entity gives error: is or contains non-shared type Text -> ()
81-
function on Entity to retrieve entityType specific fields (or a static field)
82-
work with JSON: https://github.com/Toniq-Labs/creator-nfts/blob/main/canisters/nft/main.mo
83-
UI sends in JSON encoded as Blob: https://github.com/Toniq-Labs/creator-nfts/blob/main/frontend/src/canisters/nft/minting.ts
84-
potentially String / Text also works (i.e. no en-/decoding) --> work with Text for now, probably change to Blob later (after finding out about its potential benefits)
85-
86-
Generate ID:
87-
Motoko library with example: https://github.com/aviate-labs/uuid.mo/tree/main/example
88-
import with vessel package manager: https://github.com/dfinity/vessel
89-
use synchronous:
90-
private let rr = XorShift.toReader(XorShift.XorShift64(null));
91-
private let c : [Nat8] = [0, 0, 0, 0, 0, 0]; // Replace with identifier of canister f.e.
92-
private let se = Source.Source(rr, c);
93-
let id = se.new();
94-
UUID.toText(id);
95-
to get identifier of canister: get canister principal (let canisterId = Principal.fromActor(Invoice);), Principal.toBlob(p), Blob to [Nat8] (https://forum.dfinity.org/t/type-mismatch-in-ledger-canister-and-invoice-canister/13300/4)
96-
97-
## TODOs
98-
TODO: bug in create_entity_and_bridge: Entity's and Bridge's internalIds are the same
99-
TODO: bug in create functions: canister's id is taken as owner and creator
100-
TODO: update and delete functions
101-
TODO: Replace with identifier of canister f.e.
102-
TODO: should bridge id be assignable? probably: always assign random id
103-
TODO: fill as stringified object with fields as listed in listOfEntitySpecificFieldKeys
104-
TODO: state has to be correctly assigned (e.g. Confirmed if created by Entity owner)
105-
TODO: define bridge categories
106-
TODO: determine which category's list/categories' lists in entry to return [multiple]
107-
TODO: potentially update entityToCreate fields (might vary depending on EntityType)
108-
TODO: potentially assign final internal_id to Entity (might vary depending on EntityType)
109-
TODO: possible to return promise? Would this speed up this canister? e.g. try ... : async (async Entity.Entity) [multiple, all files]

canister_ids.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"bebb": {
33
"ic": "pzrof-pyaaa-aaaai-acnha-cai",
4-
"local": "pzrof-pyaaa-aaaai-acnha-cai"
4+
"local": "pzrof-pyaaa-aaaai-acnha-cai",
5+
"development": "tsmol-tqaaa-aaaag-abt2a-cai",
6+
"testing": "t6nyb-faaaa-aaaal-qcbaa-cai"
57
}
68
}

dfx.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,19 @@
1010
"packtool": "vessel sources"
1111
}
1212
},
13+
"networks": {
14+
"development": {
15+
"providers": [
16+
"https://icp0.io"
17+
],
18+
"type": "persistent"
19+
},
20+
"testing": {
21+
"providers": [
22+
"https://icp0.io"
23+
],
24+
"type": "persistent"
25+
}
26+
},
1327
"version": 1
1428
}

src/bebb/base_entity.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ module {
2626
*/
2727
owner : Principal;
2828
/**
29-
* A human readable name? for the entity
29+
* A human readable name for the entity
3030
*/
31-
name : ?Text;
31+
name : Text;
3232
/**
3333
* An owner defined description for what the entity is
3434
*/
35-
description : ?Text;
35+
description : Text;
3636
/**
3737
* Keywords that are used to descripe the entity to
38-
* enable more efficient lookup of the entity?
38+
* enable more efficient lookup of the entity
3939
*/
40-
keywords : ?[Text];
40+
keywords : [Text];
4141
/**
4242
* Unknown
4343
*/
44-
entitySpecificFields : ?Text;
44+
entitySpecificFields : Text;
4545
/**
4646
* Unknown
4747
*/

src/bebb/bridge.mo

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ module {
128128
case null { BridgeSettings() };
129129
case (?customSettings) { customSettings };
130130
};
131-
name : ?Text = initiationObject.name;
132-
description : ?Text = initiationObject.description;
133-
keywords : ?[Text] = initiationObject.keywords;
134-
entitySpecificFields : ?Text = initiationObject.entitySpecificFields;
131+
name : Text = Option.get<Text>(initiationObject.name, "");
132+
description : Text = Option.get<Text>(initiationObject.description, "");
133+
keywords : [Text] = Option.get<[Text]>(initiationObject.keywords, []);
134+
entitySpecificFields : Text = Option.get<Text>(initiationObject.entitySpecificFields, "");
135135
listOfEntitySpecificFieldKeys : [Text] = ["bridgeType", "fromEntityId", "toEntityId"];
136136
bridgeType : BridgeType = initiationObject.bridgeType;
137137
fromEntityId : Text = initiationObject.fromEntityId;
@@ -152,9 +152,9 @@ module {
152152
creator : Principal = originalBridge.creator;
153153
owner : Principal = originalBridge.owner;
154154
settings : BridgeSettings = Option.get<BridgeSettings>(bridgeUpdateObject.settings, originalBridge.settings);
155-
name : ?Text = Option.get<?Text>(?bridgeUpdateObject.name, originalBridge.name);
156-
description : ?Text = Option.get<?Text>(?bridgeUpdateObject.description, originalBridge.description);
157-
keywords : ?[Text] = Option.get<?[Text]>(?bridgeUpdateObject.keywords, originalBridge.keywords);
155+
name = Option.get<Text>(bridgeUpdateObject.name, originalBridge.name);
156+
description : Text = Option.get<Text>(bridgeUpdateObject.description, originalBridge.description);
157+
keywords = Option.get<[Text]>(bridgeUpdateObject.keywords, originalBridge.keywords);
158158
bridgeType : BridgeType = originalBridge.bridgeType;
159159
fromEntityId : Text = originalBridge.fromEntityId;
160160
toEntityId : Text = originalBridge.toEntityId;

0 commit comments

Comments
 (0)