diff --git a/index.mjs b/index.mjs index abd6734..1946bbd 100644 --- a/index.mjs +++ b/index.mjs @@ -60,7 +60,13 @@ const Test = async (backend) => { // monitor events - ["new", "setup", "grant", "ready", "foo"].forEach((el) => { + [ + //"new", + //"setup", + "grant", + "ready", + "foo", + ].forEach((el) => { ctcAlice.e[el].monitor((ej) => { console.log("..........................................."); console.log(`${el} event!`); @@ -88,6 +94,19 @@ const Test = async (backend) => { // New + for (let i = 0; i < appCount; i++) { + console.log(`Deploying contract ${i}...`); + const ctc = await ctcAlice.a.Master.launch(tokObj.v1.id); + console.log(ctc); + console.log(stdlib.bigNumberToNumber(ctc)); + console.log("Contract deployed!"); + ctcs.push(ctc); + console.log(stdlib.bigNumberToNumber(await accAlice.balanceOf())); + console.log(stdlib.formatCurrency(await accAlice.balanceOf())); + } + + return; + for (let i = 0; i < appCount; i++) { console.log(`Deploying contract ${i}...`); const ctc = await ctcAlice.a.Master.new(); @@ -132,6 +151,8 @@ const Test = async (backend) => { console.log(await ctc.v.state()); } + return; + // Grant issuer do { @@ -196,7 +217,13 @@ const Test = async (backend) => { console.log(await ctc2.v.state()); console.log(await ctc2.v.clicks(accAlice)); console.log(await ctc2.v.clicks(accIssuer)); - await ctc.a.Master.foo4(ctcInfo, accIssuer, accAlice); // "Error: Network request error. Received status 400: TransactionPool.Remember: transaction FLPXG4MGKITBQ44O23MG6JYTS4MQUI4QVXNBXXYEHM5NLMMLKA7Q: logic eval error: logic eval error: - would result negative. Details: pc=1500, opcodes=dup\nstore 0\n-\n. Details: pc=1264, opcodes=load 16\nitxn_field Applications\nitxn_submit\n + //await ctc.a.Master.foo4(ctcInfo, accIssuer, accAlice); // "Error: Network request error. Received status 400: TransactionPool.Remember: transaction FLPXG4MGKITBQ44O23MG6JYTS4MQUI4QVXNBXXYEHM5NLMMLKA7Q: logic eval error: logic eval error: - would result negative. Details: pc=1500, opcodes=dup\nstore 0\n-\n. Details: pc=1264, opcodes=load 16\nitxn_field Applications\nitxn_submit\n + console.log(stdlib.bigNumberToNumber(await accAlice.balanceOf())); + console.log(stdlib.formatCurrency(await accAlice.balanceOf())); + console.log(await ctc2.v.state()); + console.log(await ctc2.v.clicks(accAlice)); + console.log(await ctc2.v.clicks(accIssuer)); + await ctc2.a.U0.foo5(accAlice, accIssuer); console.log(stdlib.bigNumberToNumber(await accAlice.balanceOf())); console.log(stdlib.formatCurrency(await accAlice.balanceOf())); console.log(await ctc2.v.state()); diff --git a/index.rsh b/index.rsh index 6e91f64..782ec32 100644 --- a/index.rsh +++ b/index.rsh @@ -9,21 +9,25 @@ const TokenType = Token; export const Child = Reach.App(() => { setOptions({ connectors: [ALGO] }); - const D = Participant("Deployer", {}); const Params = Object({ - ctc: Contract, token: TokenType, }); + const D = Participant("Deployer", { + getParams: Fun([], Params), + }); + /* const A = Participant("Alice", { getParams: Fun([], Params), ready: Fun([], Null), }); + */ const a = { U0: API("U0", { foo: Fun([Address], Bool), foo2: Fun([Address], Bool), foo3: Fun([Address, Address], Bool), foo4: Fun([Address, Address], Bool), + foo5: Fun([Address, Address], Bool), }), C: API("C", { grant: Fun([Address], Bool), @@ -37,15 +41,21 @@ export const Child = Reach.App(() => { const v = View({ state: Fun([], State), clicks: Fun([Address], UInt), + likes: Fun([Address, Address], UInt), }); init(); - D.publish(); + D.only(() => { + const { token } = declassify(interact.getParams()); + }); + D.publish(token); + const ctc = fromSome(Contract.fromAddress(D), getContract()) // impossible + /* commit(); A.only(() => { const { ctc, token } = declassify(interact.getParams()); }); A.publish(ctc, token); - A.interact.ready(); + */ const r = remote(ctc, { Child_ready: Fun([Contract, TokenType], Bool), Child_grant: Fun([Contract, TokenType, Address], Bool), @@ -55,17 +65,18 @@ export const Child = Reach.App(() => { const clickM = new Map(UInt); const likeM = new Map(Tuple(Address, Address), UInt); const initialState = { - constructor: A, + constructor: D, token, tokenAmount: 0, }; const [s] = parallelReduce([initialState]) .while(true) - .invariant(balance() == 0, "balance accurate") + .invariant(balance() >= 0, "balance accurate") .invariant(balance(token) == 0, "token balance accurate") .define(() => { v.state.set(() => State.fromObject(s)); v.clicks.set((addr) => fromSome(clickM[addr], 0)); + v.likes.set((addr1, addr2) => fromSome(likeM[[addr1, addr2]], 0)); }) .paySpec([token]) .api_(a.U0.foo, (addr) => { @@ -99,11 +110,23 @@ export const Child = Reach.App(() => { }) .api_(a.U0.foo4, (addr1, addr2) => { return [ + [1000000, [0, token]], (k) => { k(true); clickM[addr1] = fromSome(clickM[addr1], 0) + 1; clickM[addr2] = fromSome(clickM[addr2], 0) + 1; - likeM[[addr1, addr2]] = 0; + likeM[[addr1, addr2]] = fromSome(likeM[[addr1, addr2]], 0) + 1; // // "Error: Network request error. Received status 400: TransactionPool.Remember: transaction FLPXG4MGKITBQ44O23MG6JYTS4MQUI4QVXNBXXYEHM5NLMMLKA7Q: logic eval error: logic eval error: - would result negative. Details: pc=1500, opcodes=dup\nstore 0\n-\n. Details: pc=1264, opcodes=load 16\nitxn_field Applications\nitxn_submit\n + return [s]; + }, + ]; + }) + .api_(a.U0.foo5, (addr1, addr2) => { + return [ + (k) => { + k(true); + clickM[addr1] = fromSome(clickM[addr1], 0) + 1; + clickM[addr2] = fromSome(clickM[addr2], 0) + 1; + likeM[[addr1, addr2]] = fromSome(likeM[[addr1, addr2]], 0) + 1; return [s]; }, ]; @@ -136,8 +159,9 @@ export const Master = Reach.App(() => { }); const a = { master: API("Master", { - new: Fun([], Contract), - setup: Fun([Contract], Bool), + launch: Fun([TokenType], Contract), + //new: Fun([], Contract), + //setup: Fun([Contract], Bool), foo2: Fun([Contract, Address], Bool), foo3: Fun([Contract, Address, Address], Bool), foo4: Fun([Contract, Address, Address], Bool), @@ -150,8 +174,8 @@ export const Master = Reach.App(() => { }; const e = { child: Events({ - new: [Contract], - setup: [Contract], + //new: [Contract], + //setup: [Contract], ready: [Contract, TokenType], grant: [Contract, TokenType, Address], foo: [Contract, TokenType, Address], @@ -163,6 +187,25 @@ export const Master = Reach.App(() => { const [] = parallelReduce([]) .invariant(balance() == 0, "balance accurate") .while(true) + .api_(a.master.launch, (token) => { + check(this == A, "Must be authorized"); + return [ + minBal, + (k) => { + const ctc = new Contract(Child)([0]); + const { publish } = remote(ctc, { + publish: Fun([Bytes(4), Tuple(UInt, TokenType)], Null), + }); + publish.pay(minBal).ALGO({ rawCall: true })( + Bytes.fromHex("0x5256fdac"), // sha512/256(_reachp_0((uint64,uint64))void) + [0, token] + ); + k(ctc); + return []; + }, + ]; + }) + /* .api_(a.master.new, () => { check(this == A, "Must be authorized"); return [ @@ -174,7 +217,7 @@ export const Master = Reach.App(() => { }, ]; }) - .api_(a.master.setup, (ctc) => { + .api_(a.master.setup, (x) => { check(this == A, "Must be authorized"); return [ minBal, @@ -183,8 +226,8 @@ export const Master = Reach.App(() => { publish: Fun([Bytes(4), Tuple(UInt)], Null), }); publish.pay(minBal).ALGO({ rawCall: true })( - Bytes.fromHex("0xc194ad99"), // sha256(_reach_p0((uint64))void) - [0] + Bytes.fromHex("0xc194ad99"), // sha512/256(_reach_p0((uint64))void) + [0], ); e.child.setup(ctc); k(true); @@ -192,6 +235,7 @@ export const Master = Reach.App(() => { }, ]; }) + */ .api_(a.master.foo2, (ctc, addr) => { return [ (k) => { @@ -219,7 +263,7 @@ export const Master = Reach.App(() => { }); k( r.U0_foo3.ALGO({ - fees: 1, + fees: 10, apps: [ctc], boxes: [ [ctc, 0, addr1],