-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1309 from demergent-labs/rec_fix_example
Fix Recursive
- Loading branch information
Showing
85 changed files
with
2,123 additions
and
3,106 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,9 +1,6 @@ | ||
type rec_14 = record {txid:vec nat8; vout:nat32}; | ||
type rec_13 = record {height:nat32; value:nat64; outpoint:rec_14}; | ||
type rec_12 = record {next_page:opt vec nat8; tip_height:nat32; tip_block_hash:vec nat8; utxos:vec rec_13}; | ||
service: () -> { | ||
getBalance: (text) -> (nat64); | ||
getCurrentFeePercentiles: () -> (vec nat64); | ||
getUtxos: (text) -> (rec_12); | ||
getUtxos: (text) -> (record {next_page:opt vec nat8; tip_height:nat32; tip_block_hash:vec nat8; utxos:vec record {height:nat32; value:nat64; outpoint:record {txid:vec nat8; vout:nat32}}}); | ||
sendTransaction: (vec nat8) -> (bool); | ||
} |
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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
type rec_0 = record {someCanister:service {query1:() -> (bool) query; update1:() -> (text) }}; | ||
service: () -> { | ||
canisterParam: (service {query1:() -> (bool) query; update1:() -> (text) }) -> (service {query1:() -> (bool) query; update1:() -> (text) }) query; | ||
canisterReturnType: () -> (service {query1:() -> (bool) query; update1:() -> (text) }) query; | ||
canisterNestedReturnType: () -> (rec_0); | ||
canisterList: (vec service {query1:() -> (bool) query; update1:() -> (text) }) -> (vec service {query1:() -> (bool) query; update1:() -> (text) }); | ||
canisterCrossCanisterCall: (service {query1:() -> (bool) query; update1:() -> (text) }) -> (text); | ||
canisterCrossCanisterCall: (service {query1: () -> (bool) query; update1: () -> (text);}) -> (text); | ||
canisterList: (vec service {query1: () -> (bool) query; update1: () -> (text);}) -> (vec service {query1: () -> (bool) query; update1: () -> (text);}); | ||
canisterNestedReturnType: () -> (record {someCanister:service {query1: () -> (bool) query; update1: () -> (text);}}); | ||
canisterParam: (service {query1: () -> (bool) query; update1: () -> (text);}) -> (service {query1: () -> (bool) query; update1: () -> (text);}) query; | ||
canisterReturnType: () -> (service {query1: () -> (bool) query; update1: () -> (text);}) query; | ||
} |
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,3 @@ | ||
service: (record {text; record {id:text}}) -> { | ||
greetUser: () -> (text) query; | ||
} |
File renamed without changes.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type rec_14 = variant {Leaf; Branch:rec_14}; | ||
service: (rec_14) -> { | ||
countBranches: () -> (nat) query; | ||
} |
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,27 @@ | ||
import { Canister, init, Null, query, Recursive, Variant, nat } from 'azle'; | ||
|
||
const Node = Recursive(() => | ||
Variant({ | ||
Leaf: Null, | ||
Branch: Node | ||
}) | ||
); | ||
|
||
let tree: typeof Node = { Leaf: null }; | ||
|
||
export default Canister({ | ||
init: init([Node], (node) => { | ||
tree = node; | ||
return undefined; | ||
}), | ||
countBranches: query([], nat, () => { | ||
return countBranches(tree); | ||
}) | ||
}); | ||
|
||
function countBranches(node: typeof Node): nat { | ||
if (node.Leaf !== undefined) { | ||
return 1n; | ||
} | ||
return countBranches(node.Branch); | ||
} |
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 |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import { getCanisterId, runTests } from 'azle/test'; | ||
import { createActor } from '../test/dfx_generated/complex_init'; | ||
import { get_tests } from './tests'; | ||
import { createActor as createComplexActor } from '../test/dfx_generated/complex_init'; | ||
import { createActor as createRecActor } from '../test/dfx_generated/rec_init'; | ||
import { get_rec_tests, get_tests } from './tests'; | ||
|
||
const complexInitCanister = createActor(getCanisterId('complex_init'), { | ||
const complexInitCanister = createComplexActor(getCanisterId('complex_init'), { | ||
agentOptions: { | ||
host: 'http://127.0.0.1:8000' | ||
} | ||
}); | ||
|
||
runTests(get_tests(complexInitCanister)); | ||
const recInitCanister = createRecActor(getCanisterId('rec_init'), { | ||
agentOptions: { | ||
host: 'http://127.0.0.1:8000' | ||
} | ||
}); | ||
|
||
runTests([ | ||
...get_tests(complexInitCanister), | ||
...get_rec_tests(recInitCanister) | ||
]); |
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,41 @@ | ||
import { Record, Null, text, Variant, Vec, Recursive } from 'azle'; | ||
|
||
export const ReactionType = Variant({ | ||
Fire: Null, | ||
ThumbsUp: Null, | ||
ThumbsDown: Null | ||
}); | ||
|
||
export const User = Recursive(() => | ||
Record({ | ||
id: text, | ||
posts: Vec(Post), | ||
reactions: Vec(Reaction), | ||
threads: Vec(Thread), | ||
username: text | ||
}) | ||
); | ||
|
||
export const Post = Recursive(() => | ||
Record({ | ||
id: text, | ||
author: User, | ||
reactions: Vec(Reaction), | ||
text: text, | ||
thread: Thread | ||
}) | ||
); | ||
|
||
export const Thread = Record({ | ||
id: text, | ||
author: User, | ||
posts: Vec(Post), | ||
title: text | ||
}); | ||
|
||
export const Reaction = Record({ | ||
id: text, | ||
author: User, | ||
post: Post, | ||
reactionType: ReactionType | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.