var steem = require("steem");

/*var creator = 'jblew';
var creatorWif = '';

var newAccountName = 'stagingwisevote.app';
var newAccountPassword = '';

var publicKeys = steem.auth.generateKeys(newAccountName, newAccountPassword, ['posting', 'owner', 'active', 'memo']);

var owner = {
    weight_threshold: 1,
    account_auths: [],
    key_auths: [[publicKeys.owner, 1]]
};
var active = {
    weight_threshold: 1,
    account_auths: [],
    key_auths: [[publicKeys.active, 1]]
};
var posting = {
    weight_threshold: 1,
    account_auths: [],
    key_auths: [[publicKeys.posting, 1]]
};


steem.api.getConfig(function(err, config) {
  if(err){
    console.log(err, config);
    throw new Error(err);
  }

  steem.api.getChainProperties(function(err2, chainProps) {
    if(err2){
      console.log(err2, chainProps);
      throw new Error(err2);
    }

    //var ratio = config['STEEMIT_CREATE_ACCOUNT_WITH_STEEM_MODIFIER'];
    //var fee = Asset.from(chainProps.account_creation_fee).multiply(ratio);

    var feeString = "3.000 STEEM"; //fee.toString();
    var jsonMetadata = '';

    steem.broadcast.accountCreate(creatorWif, feeString, creator, 
                newAccountName, owner, active, posting, publicKeys.memo, 
                jsonMetadata, function(err, result) {
      console.log(err, result);
    });
  });
});*/

/*const op = [
    'transfer_to_vesting',
    {
        from: "wise.vote",
        to: "wise.vote",
        amount: "3.000 STEEM",
    },
];

const privateKey = "5Hz8dnEnd4wDzipBGSYMeEgcbBtpHdhj71F3spRqUQbNW5qPoEM";
steem.broadcast.sendAsync(
    { extensions: [], operations: [ op ] },
    { active: privateKey }
).then(
    function(result) {
        console.log(result);
        console.log(JSON.stringify(result, undefined, 2));
    },
    function(error) {
        console.error(error);
    }
);*/

const jsonObj = 	["v2:send_voteorder",{
    "delegator":"jblew","ruleset":"hehe","author":"noisy",
    "permlink":"what-steem-can-learn-from-linux-and-git-few-words-about-decentralization-from-linus-torvalds","weight":10000
}];
const op = ["custom_json", {
    id: "wise",
    json: JSON.stringify(jsonObj),
    required_auths: [],
    required_posting_auths: [ "wise-test5" ]
}];

const privateKey = "5KintdAiYqL1FKZjtLsqe2BsgNDo4qhiD3SGwfFyZvWyaQFAPHX";
steem.broadcast.sendAsync(
    { extensions: [], operations: [ op ] },
    { posting: privateKey }
).then(
    function(result) {
        console.log(result);
        console.log(JSON.stringify(result, undefined, 2));
    },
    function(error) {
        console.error(error);
    }
);

