Skip to content

Commit

Permalink
add demo application
Browse files Browse the repository at this point in the history
  • Loading branch information
snjax committed Feb 6, 2020
1 parent da866e0 commit e52c1fd
Show file tree
Hide file tree
Showing 11 changed files with 1,289 additions and 5 deletions.
61 changes: 61 additions & 0 deletions zwaves_demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
46 changes: 46 additions & 0 deletions zwaves_demo/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const fetch = require("node-fetch");
const { broadcast, waitForTx, setScript, invokeScript } = require("@waves/waves-transactions");
const { address, base58Encode, publicKey } = require("@waves/waves-crypto");
const fs = require("fs");
const {extract_vk} = require("../zwaves_node/lib/index.js");



const env = process.env;
if (env.NODE_ENV !== 'production') {
require('dotenv').load();
}




const seed = env.MNEMONIC;
const rpc = env.WAVES_RPC;
const chainId = env.WAVES_CHAINID;
const dApp = address(env.MNEMONIC, chainId);

const ridetpl = fs.readFileSync("ride/zwaves.ride", {encoding:"utf8"});
const transfer_mpc = fs.readFileSync("../zwaves_setup/mpc_params_transfer");
const accumulator_mpc = fs.readFileSync("../zwaves_setup/mpc_params_accumulator");




(async () => {
const ridescript = ridetpl
.replace(`let transferVK=base58''`, `let transferVK=base58'${base58Encode(extract_vk(transfer_mpc))}'`)
.replace(`let utxoAccumulatorVK=base58''`, `let utxoAccumulatorVK=base58'${base58Encode(extract_vk(accumulator_mpc))}'`)


let request = await fetch(`${env.WAVES_RPC}utils/script/compile`, { method: "POST", body: ridescript })
const {script} = await request.json();


let tx = setScript({ script, fee: 1400000, chainId}, seed);
await broadcast(tx, rpc);
await waitForTx(tx.id, { apiBase: rpc });

console.log(`Dapp is deployed with public key ${publicKey(seed)}. Specify DAPP property at .env file.`)

process.exit();
})();
Loading

0 comments on commit e52c1fd

Please sign in to comment.