Open dckc opened 4 years ago
as of 211b1d6, it can do the imports:
~/projects/js2rho/examples$ npm test
...
==== TEST CASE: StakingPool
js input: 2535 /**
* StakingPool contract
*
* This is reverse-translated
DEBUG: js.type Program
{ Program: 7 }
DEBUG: js.type BlockStatement
BlockStatement @@not impl: ...
new deployResult(`rho:rchain:deployId`),
RevAddress(`rho:rev:address`),
regInsert(`rho:registry:insertArbitrary`),
registryLookup(`rho:registry:lookup`),
console(`rho:io:stdout`)
in {
"BlockStatement"
}
more progress ... 31e21ad produces the following (with a little help from emacs for indenting)
new deployResult(`rho:rchain:deployId`),
RevAddress(`rho:rev:address`),
regInsert(`rho:registry:insertArbitrary`),
registryLookup(`rho:registry:lookup`),
console(`rho:io:stdout`)
in {
new CallExpression_32c8_0,
CallExpression_33c8_1
in {
registryLookup!("rho:rchain:authKey", CallExpression_32c8_0)
| registryLookup!("rho:rchain:revVault", CallExpression_33c8_1)
| for(AuthKey <- CallExpression_32c8_0;
RevVault <- CallExpression_33c8_1) {
contract StakingPool(@{ "create" }, unsealer, __return) = {
new unf
in {
new CallExpression_40c16_2,
CallExpression_41c16_3
in {
RevAddress!("fromUnforgeable", *unf, CallExpression_40c16_2)
| RevVault!("unforgeableAuthKey", *unf, CallExpression_41c16_3)
| for(revVaultAuthKey <- CallExpression_40c16_2;
revAddr <- CallExpression_41c16_3) {
"TODO@@ ExpressionStatement"
}
}
}
}
}
}
}
it now (9a11661) generates the following, modulo a couple manual fixes for patterns (as well as indentation):
new deployResult(`rho:rchain:deployId`),
RevAddress(`rho:rev:address`),
regInsert(`rho:registry:insertArbitrary`),
registryLookup(`rho:registry:lookup`),
console(`rho:io:stdout`)
in {
new CallExpression_32c8_0,
CallExpression_33c8_1
in {
registryLookup!("rho:rchain:authKey", *CallExpression_32c8_0)
| registryLookup!("rho:rchain:revVault", *CallExpression_33c8_1)
| for(AuthKey <- CallExpression_32c8_0;
RevVault <- CallExpression_33c8_1) {
new StakingPool
in {
contract StakingPool(@{ "create" }, unsealer, __return) = {
new unf
in {
new CallExpression_40c16_2,
CallExpression_41c16_3
in {
RevAddress!("fromUnforgeable", *unf, *CallExpression_40c16_2)
| RevVault!("unforgeableAuthKey", *unf, *CallExpression_41c16_3)
| for(revVaultAuthKey <- CallExpression_40c16_2;
revAddr <- CallExpression_41c16_3) {
console!({"new staking pool rev addr": *revAddr, "authKey": *revVaultAuthKey})
|
new AwaitExpression_44c42_4
in {
RevVault!("findOrCreate", *revAddr, *AwaitExpression_44c42_4)
// TODO: pattern: @(true, *vault)
| for(@(true, *vault) <- AwaitExpression_44c42_4) {
console!({"vault": *vault})
|
new self
in {
contract self(@{ "redeem" }, targetAddr, amount, sealedOrder, _return, __return) = {
console!({"redeem target": *targetAddr, "amount": *amount, "sealedOrder": *sealedOrder})
|
new AwaitExpression_52c50_6
in {
unsealer!(*sealedOrder, *AwaitExpression_52c50_6)
// TODO: pattern: @(*ok, *order)
| for(@(*ok, *order) <- AwaitExpression_52c50_6) {
console!({"ok": *ok, "order": *order})
| "TODO@@ IfStatement"
}
}
}
| __return!(bundle+{*self})
}
}
}
}
}
}
}
|
new AwaitExpression_66c16_8
in {
regInsert!(bundle+{*StakingPool}, *AwaitExpression_66c16_8)
| for(uri <- AwaitExpression_66c16_8) {
console!({"StakingPool uri": *uri})
| deployResult!(*uri)
}
}
}
}
}
}
cc @tgrospic
I think I got it! 12ea664
I'm collaborating on a staking pool contract in Rholang, but the Rholang dev tools are so primitive that it's painful.
So I'm working on expanding this compiler to handle it.
I took StakingPool.rho and converted it back to .js by hand: StakingPool.js.