-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.mjs
56 lines (47 loc) · 1.99 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {loadStdlib, ask} from '@reach-sh/stdlib';
import * as backend from './build/index.main.mjs';
const stdlib = loadStdlib(process.env);
const startingBalance = stdlib.parseCurrency(100);
const [ accOwner, accContractor, accSupplier ] = await stdlib.newTestAccounts(3, startingBalance);
const [ addressOwner, addressContractor, addressSupplier ] = [ accOwner.getAddress(), accContractor.getAddress(), accSupplier.getAddress() ];
console.log(` Owner address: ${addressOwner} Contractor address: ${addressContractor} Supplier address: ${addressSupplier}`);
console.log(`Initialised participant accounts with ${startingBalance}`);
console.log('Launching...');
const ctcOwner = accOwner.contract(backend);
const ctcContractor = accContractor.contract(backend, ctcOwner.getInfo());
const deadline = 50;
const commonInterface = {
displayFunds: async (funds, address) => {
console.log(`Contract transferred ${funds} to Supplier ${address} `);
console.log(`Owner balance: ${await accOwner.balanceOf()} Contractor balance: ${await accContractor.balanceOf()} Supplier balance: ${await accSupplier.balanceOf()}
`);
}
}
console.log('Starting backends...');
await Promise.all([
backend.Owner(ctcOwner, {
...stdlib.hasRandom,
...commonInterface,
supplier: async () => {
const address = await ask.ask(`kindly provide the contract address of the supplier you want to pay:`, (x => x));
return address;
},
informTimeOut: async () => {
await stdlib.wait(deadline);
console.log(`valid time exceeded!`)
}
}),
backend.Contractor(ctcContractor, {
...stdlib.hasRandom,
...commonInterface,
// implement Bob's interact object here
wagerToPay: async () => {
console.log(`Contractor (${accContractor.getAddress()}) balance before: ${await accContractor.balanceOf()}`)
const funds = await ask.ask(`Enter wager for project:`, parseInt);
console.log(`You paid wager ${funds}!`)
return funds;
}
}),
]);
ask.done();
console.log('Goodbye');