Commit bdfff40a authored by Adrien Béraud's avatar Adrien Béraud

scripts: update for new contract

Change-Id: I5741f072e11057d94a84540df4a6bbf67a0df125
parent 4af9851e
#!/usr/bin/env nodejs
var BigNumber = require('bignumber.js');
var fs = require('fs');
var Web3 = require('web3');
......@@ -10,7 +9,7 @@ web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
var REG_ADDR_FILE = "contractAddress.txt";
var REG_ADDR = "0xe53cb2ace8707526a5050bec7bcf979c57f8b44f";
var REG_ABI_registerFor = ['bytes32', 'address', 'address'];
var REG_ABI_reserveFor = ['bytes32', 'address', 'address', 'string', 'string'];
var NAME_LIST = [];
function readContractAddress() {
fs.readFile(REG_ADDR_FILE, function(err, content) {
......@@ -37,10 +36,15 @@ function getAllNames() {
try {
var tr = block.transactions[t];
if (tr.to == REG_ADDR) {
var p = web3.SolidityCoder.decodeParams(REG_ABI_registerFor, tr.input.substr(10));
var n = web3.toUtf8(p[0]);
const p = web3.SolidityCoder.decodeParams(REG_ABI_reserveFor, tr.input.substr(10));
const n = web3.toUtf8(p[0]);
console.log("Entry: " + n + " -> " + p[1] + " " + p[2]);
NAME_LIST.push({"name": n,"addr":p[2], "owner":p[1]});
const newObj = {"name": n,"addr":p[2], "owner":p[1]};
if (p[3])
newObj["publickey"] = p[3];
if (p[4])
newObj["signature"] = p[4];
NAME_LIST.push(newObj);
} else {
console.log("Wrong contract: " + tr.to + " expected " + REG_ADDR);
}
......
......@@ -21,7 +21,6 @@ var providedPath = String(argv['_'][0])
batchInputFile = validateFile(providedPath);
if(!batchInputFile)
throw "File " + providedPath + " does not exist"
Object.getPrototypeOf(web3.eth).awaitConsensus = function(txhash, mined_cb) {
......@@ -140,7 +139,7 @@ function formatAddress(address) {
}
return undefined;
}
function registerName(addressparam, nameparam, ownerparam, mined_cb){
function registerName(addressparam, nameparam, ownerparam, pk, sig, mined_cb){
try {
var addr = formatAddress(addressparam);
if (!addr) {
......@@ -174,7 +173,7 @@ function registerName(addressparam, nameparam, ownerparam, mined_cb){
} else {
console.log("Remaing gaz: " + getRemainingGaz());
unlockAccount();
reg.reserveFor.sendTransaction(formatName(nameparam), ownerparam, addr, {
reg.reserveFor.sendTransaction(formatName(nameparam), ownerparam, addr, pk, sig, {
from: coinbase,
gas: 3000000
}, function(terr, reg_c) {
......@@ -226,7 +225,7 @@ function startWrites(){
console.log(String(NAME_LIST.length) + " inserts to do");
//create parallel queue that does 256 registerNames parallely
var q = async.queue(function(task, callback) {
registerName(task['addr'], task['name'], task['owner'], callback);
registerName(task['addr'], task['name'], task['owner'], task['publickey'], task['signature'], callback);
}, 256);
for (var i = 0; i < NAME_LIST.length; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment