Skip to content

Commit

Permalink
fix things
Browse files Browse the repository at this point in the history
  • Loading branch information
mebyz committed Feb 2, 2019
1 parent 939fb1d commit e83fb97
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion integrationTest.rho
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ new myRhobustContractTEST, ack, stdoutAck(`rho:io:stdoutAck`) in {

stdoutAck!("TEST : Creating sample rhobust contract. 3 agents (employer, employee, IRS)", *ack)
| // <- concurrent (log test start)
@"rhobustFactory008"!(*myRhobustContractTEST, 3)
@"rhobustFactory012"!(*myRhobustContractTEST, 3)
| // <- concurrent (run test)
// This levels of recursivity is only needed to simulate a sequential test.
// In real life, agents interact INDEPENDENTLY and sometimes CONCURRENTLY.
Expand Down
28 changes: 16 additions & 12 deletions rhobustCaller.rho
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
new
doubler,
uriChan,
contractCh,ct,
contractCh,

stdout(`rho:io:stdout`),
ri(`rho:registry:insertArbitrary`),
Expand Down Expand Up @@ -44,11 +44,11 @@ resProc_Boss,ackProc_Boss,
ackwithdraw,
acktaxPay,
ackprocessIncomeTax,
RhobustContractSign,ackRhobustContractSign
RhobustContractSign,ackRhobustContractSign,ackPay
in {


contract @"rhobustFactory008"(rhobustCreation, @n, result) = {
contract @"rhobustFactory012"(rhobustCreation, @n, result) = {
new
ri(`rho:registry:insertArbitrary`),
rl(`rho:registry:lookup`) in {
Expand All @@ -74,7 +74,7 @@ in {
}
} |

contract @"rhobustFactory008"(rhobustLookup, @uri, @action, @name, @key, resultLookup) = {
contract @"rhobustFactory012"(rhobustLookup, @uri, @action, @name, @key, resultLookup) = {
// resultLookup!(uri)
rl!(uri, *contractCh) |
for( ct <- contractCh) {
Expand All @@ -94,7 +94,7 @@ in {
new myRhobustContractTEST, myRhobustContract_Joe , myRhobustContract_Irs , myRhobustContract_Boss, ack,
stdout(`rho:io:stdout`), stdoutAck(`rho:io:stdoutAck`) in {
stdout!("TEST STEP 1 : Creating sample rhobust contract") |
@"rhobustFactory008"!(*myRhobustContractTEST, 3, *ack) |
@"rhobustFactory012"!(*myRhobustContractTEST, 3, *ack) |
for(@uri2 <- ack) {
//stdout!(uri2) |

Expand All @@ -107,23 +107,23 @@ in {

// Later on, agent A (Joe) logs in to sign the contract
// this results in a lookup in the tuplespace using uri
@"rhobustFactory008"!(*myRhobustContract_Joe, uri2,"sign", "Joe","secretkey_employee", *ackJoe) |
@"rhobustFactory012"!(*myRhobustContract_Joe, uri2,"sign", "Joe","secretkey_employee", *ackJoe) |
for(resJoe <- ackJoe) {
stdout!(*resJoe) |



// Later on, agent B (irs) logs in to sign the contract
// this results in a lookup in the tuplespace using uri
@"rhobustFactory008"!(*myRhobustContract_Irs, uri2,"sign", "irs","secretkey_irs", *ackIrs) |
@"rhobustFactory012"!(*myRhobustContract_Irs, uri2,"sign", "irs","secretkey_irs", *ackIrs) |
for(resIrs <- ackIrs) {
stdout!(*resIrs) |



// Later on, agent C (boss) logs in to sign the contract
// this results in a lookup in the tuplespace using uri
@"rhobustFactory008"!(*myRhobustContract_Boss, uri2,"sign", "boss","secretkey_employer", *ackBoss) |
@"rhobustFactory012"!(*myRhobustContract_Boss, uri2,"sign", "boss","secretkey_employer", *ackBoss) |
for(resBoss <- ackBoss){
stdout!(*resBoss)

Expand Down Expand Up @@ -172,9 +172,11 @@ in {

if (agentType == "boss" and secretKey == "secretkey_employer") {
// agent A (Employer) has been identified
pay!(*invoiceId, *invoiceName, *invoiceAmount, "Joe", 100)
| // <- concurrent
logResolve!("Hello " ++ agentType ++ ", let's pay Joe. transaction will be fullfiled using your key ${secretKey}" %% {"secretKey": secretKey}, *ackSign)
pay!(*invoiceId, *invoiceName, *invoiceAmount, "Joe", 100,"Hello " ++ agentType ++ " you just paid Joe. transaction fullfiled using your key ${secretKey}" %% {"secretKey": secretKey}, *ackPay)
|
for (@hs<- ackPay) {
ackSign!(hs)
}
} else
if (agentType == "Joe" and secretKey == "secretkey_employee") {
// agent B (Employee) has been identified
Expand Down Expand Up @@ -230,7 +232,7 @@ in {
} |

// agent A (Employer) behaviour : pay
contract pay(pId, pName, pAmount, @name,@amount) = {
contract pay(pId, pName, pAmount, @name,@amount,@message, ackEnd) = {
new Y, H in {
// generate new transaction hash key
@"keccak256Hash"!(name.toByteArray(), *Y)
Expand All @@ -240,6 +242,8 @@ in {
|
// fullfill the payment (4 independent processes are spawned)
pId!(H) | pName!(name) | pAmount!(amount) |

ackEnd!([H,message,name,amount]) |

// when a payment occurs, these three actions are triggered .. CONCURRENTLY !!
for(@paymentId <- invoiceId;@paymentName <- invoiceName;@amount <- invoiceAmount) {
Expand Down
4 changes: 2 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ app.listen(uiPort, () => {
app.post('/register', (req, res) => {

let ack = Math.random().toString(36).substring(7)
let code = `@"rhobustFactory008"!("${req.body.id}", ${req.body.n}, "${ack}")`
let code = `@"rhobustFactory012"!("${req.body.id}", ${req.body.n}, "${ack}")`
console.log(code)
let deployData = {term: code,
timestamp: new Date().valueOf(),
Expand Down Expand Up @@ -67,7 +67,7 @@ app.post('/call', (req, res) => {
// TODO this should be unforgeable. Can I make one from JS?
let ack = Math.random().toString(36).substring(7)
//console.log(req.body)
let code = `@"rhobustFactory008"!("${req.body.id}","${req.body.uri}","sign","${req.body.name}","${req.body.key}", "${ack}")`
let code = `@"rhobustFactory012"!("${req.body.id}","${req.body.uri}","sign","${req.body.name}","${req.body.key}", "${ack}")`
console.log(code)
let deployData = {term: code,
timestamp: new Date().valueOf(),
Expand Down

0 comments on commit e83fb97

Please sign in to comment.