Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Allow user to choose asset with which to pay fees #356
let fee_asset = chain_fee_asset.toJS();
// Default to CORE in case of faulty core_exchange_rate
if (
fee_asset.options.core_exchange_rate.base.asset_id ===
"1.3.0" &&
fee_asset.options.core_exchange_rate.quote.asset_id ===
"1.3.0"
) {
fee_asset_id = "1.3.0";
}
let tr = null;
if (transactionBuilder == null) {
tr = new TransactionBuilder();
} else {
tr = transactionBuilder;
}
let transfer_op = tr.get_type_operation("transfer", {
fee: {
amount: 0,
asset_id: fee_asset_id
},
from: chain_from.get("id"),
to: chain_to.get("id"),
amount: {amount, asset_id: chain_asset.get("id")},
memo: memo_object
});
if (__DEV__) {
console.log("built transfer", transfer_op, tr);
fee: {amount: "0", asset_id: "1.3.0"},
deposit_to_account: account.get("id"),
balance_to_claim: balance.id,
balance_owner_key: public_key_string,
total_claimed: {
amount: total_claimed,
asset_id: balance.balance.asset_id
}
});
}
// if( ! balance_claims.length) {
// throw new Error("No balances to claim");
// }
//DEBUG console.log('... balance_claims',balance_claims)
let tr = new TransactionBuilder();
for (let balance_claim of balance_claims) {
tr.add_type_operation(
"balance_claim",
balance_claim
);
}
// With a lot of balance claims the signing can take so Long
// the transaction will expire. This will increase the timeout...
tr.set_expire_seconds(15 * 60 + balance_claims.length);
return WalletDb.process_transaction(
tr,
Object.keys(signer_pubkeys),
broadcast
).then(result => {
dispatch(true);
nonce,
memo
) :
Buffer.isBuffer(memo) ? memo.toString("utf-8") : memo
}
}
// Allow user to choose asset with which to pay fees #356
let fee_asset = chain_fee_asset.toJS();
// Default to CORE in case of faulty core_exchange_rate
if( fee_asset.options.core_exchange_rate.base.asset_id === "1.3.0" &&
fee_asset.options.core_exchange_rate.quote.asset_id === "1.3.0" ) {
fee_asset_id = "1.3.0";
}
let tr = new TransactionBuilder()
let transfer_op = tr.get_type_operation("transfer", {
fee: {
amount: 0,
asset_id: fee_asset_id
},
from: chain_from.get("id"),
to: chain_to.get("id"),
amount: { amount, asset_id: chain_asset.get("id") },
memo: memo_object
});
//console.info.info.info('transfer_op',transfer_op);
if( propose_account ) {
tr.add_type_operation("proposal_create", {
proposed_ops: [{ op: transfer_op }],
transfer({
// OBJECT: { ... }
from_account,
to_account,
amount,
asset,
memo,
broadcast = true,
encrypt_memo = true,
optional_nonce = null,
propose_account = null,
fee_asset_id = "1.3.0",
transactionBuilder = null
}) {
if (transactionBuilder == null) {
transactionBuilder = new TransactionBuilder();
}
return this._create_transfer_op({
from_account,
to_account,
amount,
asset,
memo,
propose_account,
encrypt_memo,
optional_nonce,
fee_asset_id,
transactionBuilder
}).then(transfer_obj => {
return transactionBuilder
.update_head_block()
.then(() => {
return new Promise((resolve, reject) => {
let tr = new TransactionBuilder();
const core = ChainStore.getAsset("1.3.0");
if (!core)
reject(new Error("Can't find core asset, please try again"));
let precision = Math.pow(10, core.get("precision"));
const owner = ChainStore.getAccount(account).get("id");
if (!owner)
reject(
new Error("Can't find the owner account, please try again")
);
try {
tr.add_type_operation("worker_create", {
fee: {
amount: 0,
asset_id: 0
return WalletUnlockActions.unlock().then(() => {
let proposer = null;
let transfers = [];
let tr = new TransactionBuilder();
list_of_transfers.forEach(transferData => {
transferData.transactionBuilder = tr;
transfers.push(this._create_transfer_op(transferData));
});
return Promise.all(transfers)
.then(result => {
return tr.update_head_block().then(() => {
let propose = [];
result.forEach((item, idx) => {
if (list_of_transfers[idx].propose_account) {
if (proposer == null) {
proposer = item.chain_propose_account;
}
propose.push({op: item.transfer_op});
} else {
tr.add_operation(item.transfer_op);
nonce,
message: encrypt_memo
? Aes.encrypt_with_checksum(
memo_sender.private_key,
memo_to.public_key,
nonce,
memo
)
: Buffer.isBuffer(memo)
? memo.toString("utf-8")
: memo
};
}
}
let transactionBuilder = new TransactionBuilder();
let op = transactionBuilder.get_type_operation(
"withdraw_permission_claim",
{
fee: {
amount: 0,
asset_id: objects.feeAsset.get("id")
},
withdraw_permission: withdrawPermissionId,
withdraw_from_account: objects.from.get("id"),
withdraw_to_account: objects.to.get("id"),
amount_to_withdraw: {
amount: claimAssetAmount,
asset_id: objects.claimAsset.get("id")
},
memo: memo_object ? memo_object : undefined
}
claimVestingBalance(account, cvb, forceAll = false) {
let tr = new TransactionBuilder();
let balance = cvb.balance.amount,
earned = cvb.policy[1].coin_seconds_earned,
vestingPeriod = cvb.policy[1].vesting_seconds,
availablePercent =
(forceAll || vestingPeriod) === 0 ||
cvb.balance_type == "market_fee_sharing"
? 1
: earned / (vestingPeriod * balance);
tr.add_type_operation("vesting_balance_withdraw", {
fee: {amount: "0", asset_id: "1.3.0"},
owner: account,
vesting_balance: cvb.id,
amount: {
amount: Math.floor(balance * availablePercent),
claimVestingBalance(account, cvb, forceAll = false) {
let tr = new TransactionBuilder();
let balance = cvb.balance.amount,
earned = cvb.policy[1].coin_seconds_earned,
vestingPeriod = cvb.policy[1].vesting_seconds,
availablePercent = forceAll ? 1 : earned / (vestingPeriod * balance);
tr.add_type_operation("vesting_balance_withdraw", {
fee: {amount: "0", asset_id: "1.3.0"},
owner: account,
vesting_balance: cvb.id,
amount: {
amount: Math.floor(balance * availablePercent),
asset_id: cvb.balance.asset_id
}
});
]).then((res)=> {
let [ chain_registrar, chain_referrer ] = res;
let tr = new TransactionBuilder();
tr.add_type_operation("account_create", {
fee: {
amount: 0,
asset_id: 0
},
"registrar": chain_registrar.get("id"),
"referrer": chain_referrer.get("id"),
"referrer_percent": referrer_percent,
"name": new_account_name,
"owner": {
"weight_threshold": 1,
"account_auths": [],
"key_auths": [[ owner_pubkey, 1 ]],
"address_auths": []
},
"active": {