Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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!`);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -132,6 +151,8 @@ const Test = async (backend) => {
console.log(await ctc.v.state());
}

return;

// Grant issuer

do {
Expand Down Expand Up @@ -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());
Expand Down
74 changes: 59 additions & 15 deletions index.rsh
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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) => {
Expand Down Expand Up @@ -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];
},
];
Expand Down Expand Up @@ -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),
Expand All @@ -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],
Expand All @@ -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 [
Expand All @@ -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,
Expand All @@ -183,15 +226,16 @@ 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);
return [];
},
];
})
*/
.api_(a.master.foo2, (ctc, addr) => {
return [
(k) => {
Expand Down Expand Up @@ -219,7 +263,7 @@ export const Master = Reach.App(() => {
});
k(
r.U0_foo3.ALGO({
fees: 1,
fees: 10,
apps: [ctc],
boxes: [
[ctc, 0, addr1],
Expand Down