Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #33 from Zilliqa/feature/32_deployment
Browse files Browse the repository at this point in the history
Contract deployment for non-zero balances
  • Loading branch information
edison0xyz authored Sep 3, 2018
2 parents b77b3b5 + 82ca8de commit 727a094
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 98 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ Methods that are NOT supported:
* `GetLatestDsBlock`
* `GetLatestTxBlock`

In addition, multi-contract calls are not supported yet.
In addition, the following features are not supported yet:
* Multi-contract calls
* Events

## Installation
Run `npm install`, then `node server.js`.
Expand Down
35 changes: 21 additions & 14 deletions components/scilla/scilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,11 @@

const fs = require('fs');
const utilities = require('../../utilities');
const config = require('../../config');
const LOG_SCILLA = require('debug')('kaya:scilla');
let blockchain_path = 'tmp/blockchain.json'
let colors = require('colors');


const template_state = [
{
"vname": "_balance",
"type": "Uint128",
"value": "0"
}
];


function pad(number, length) {
var str = '' + number;
while (str.length < length) {
Expand Down Expand Up @@ -62,9 +53,25 @@ const makeBlockchainJson = (val) => {
LOG_SCILLA(`blockchain.json file prepared for blocknumber: ${val}`);
}

const initializeContractState = (amt) => {
let initState = [
{
"vname": "_balance",
"type": "Uint128",
"value": amt.toString()
}
]
return initState;
}


const runScillaInterpreterSync = (command) => {
// Run Scilla Interpreter
if(!fs.existsSync(config.scilla.runner_path)) {
LOG_SCILLA('Scilla runner not found. Hint: Have you compiled the scilla binaries?');
throw new Error('Kaya RPC Runtime Error: Scilla-runner not found');
}

const exec = require('child_process').execSync;
const child = exec(command,
(error, stdout) => {
Expand All @@ -89,7 +96,7 @@ module.exports = {

if (isCodeDeployment) {
// initialized with standard message template
cmd = `./components/scilla/scilla-runner -iblockchain ${blockchain_path} -o tmp/${contractAddr}_out.json`;
cmd = `${config.scilla.runner_path} -iblockchain ${blockchain_path} -o tmp/${contractAddr}_out.json`;
isCodeDeployment = true;

init_path = `${dir}${contractAddr}_init.json`;
Expand All @@ -109,7 +116,6 @@ module.exports = {
fs.writeFileSync(init_path, cleaned_params);

} else {
// todo: check for contract
contractAddr = payload.to;
cmd = `./components/scilla/scilla-runner -iblockchain ${blockchain_path} -o tmp/${contractAddr}_out.json`;
LOG_SCILLA(`Calling transition within contract ${payload.to}`);
Expand Down Expand Up @@ -154,9 +160,10 @@ module.exports = {
if (!isCodeDeployment) {
fs.writeFileSync(`${dir}${contractAddr}_state.json`, JSON.stringify(retMsg.states));
} else {
LOG_SCILLA(`Contract has been initialized with template state`);
fs.writeFileSync(`${dir}${contractAddr}_state.json`, JSON.stringify(template_state));
fs.writeFileSync(`${dir}${contractAddr}_state.json`, JSON.stringify(initializeContractState(payload.amount)));
LOG_SCILLA(`Contract has been initialized with balance: ${payload.amount}`);
}
initializeContractState(11);
LOG_SCILLA(`State logged down in ${contractAddr}_state.json`)

console.log(`Contract Address Deployed: ` + `${contractAddr}`.green);
Expand Down
4 changes: 4 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ config.wallet = {
defaultNonce: 0
}

config.scilla = {
runner_path: './components/scilla/scilla-runner'
}

config.testconfigs = {
gasPrice: 1,
gasLimit: 10,
Expand Down
Loading

0 comments on commit 727a094

Please sign in to comment.