def QFundFeePool(self, asset_id, amount_num, source_account, fee_asset=None, isolator=None): iso = isolator blockchain_instance = iso.bts tx = TransactionBuilder(blockchain_instance=blockchain_instance) src_account = iso.getAccount(source_account) amount = iso.getAmount(amount_num, asset_id).json() params = { "from_account": iso.getAccount(source_account)['id'], "asset_id": amount["asset_id"], "amount": int(amount["amount"]), } if fee_asset: params['fee'] = iso.getAmount(0, fee_asset).json() else: params['fee'] = {"amount": 0, "asset_id": "1.3.0"} from pprint import pprint print("USE:") pprint(params) tx.appendOps(Asset_fund_fee_pool(**params)) if iso.bts.wallet.locked(): tx.addSigningInformation(src_account, "active", lazy=True) else: tx.appendSigner(src_account, "active", lazy=True) win = QTransactionBuilder(trxbuffer=tx, iso=isolator) return win.exec_()
def QUpgradeAccount(self, account_name, fee_asset=None, isolator=None): iso = isolator blockchain_instance = iso.bts tx = TransactionBuilder(blockchain_instance=blockchain_instance) src_account = iso.getAccount(account_name) params = { "account_to_upgrade": src_account['id'], "upgrade_to_lifetime_member": True, } if fee_asset: params['fee'] = iso.getAmount(0, fee_asset).json() else: params['fee'] = {"amount": 0, "asset_id": "1.3.0"} from pprint import pprint print("USE:") pprint(params) tx.appendOps(Account_upgrade(**params)) if iso.bts.wallet.locked(): tx.addSigningInformation(src_account, "active", lazy=True) else: tx.appendSigner(src_account, "active", lazy=True) win = QTransactionBuilder(trxbuffer=tx, iso=isolator) return win.exec_()
def QUpdateAccount(self, account_name, owner_key, active_key, memo_key, voting_account, num_witness, num_committee, votes, fee_asset=None, isolator=None): iso = isolator blockchain_instance = iso.bts tx = TransactionBuilder(blockchain_instance=blockchain_instance) src_account = iso.getAccount(account_name) dst_account = iso.getAccount(voting_account) params = { "account": src_account['id'], } from bitshares.blind import key_permission role = "active" if owner_key: owner_auth = key_permission(owner_key) params["owner"] = owner_auth role = "owner" if active_key: active_auth = key_permission(active_key) params["active"] = active_auth role = "owner" if not (votes is None): params["new_options"] = { "voting_account": dst_account["id"], "memo_key": memo_key if memo_key else src_account["options"]["memo_key"], "votes": votes, "num_witness": num_witness, "num_committee": num_committee, } if fee_asset: params['fee'] = iso.getAmount(0, fee_asset).json() else: params['fee'] = {"amount": 0, "asset_id": "1.3.0"} from pprint import pprint print("USE:") pprint(params) tx.appendOps(Account_update(**params)) if iso.bts.wallet.locked(): tx.addSigningInformation(src_account, role, lazy=True) else: tx.appendSigner(src_account, role, lazy=True) win = QTransactionBuilder(trxbuffer=tx, iso=isolator) return win.exec_()
def flood(ctx, account, ops, txs, to): from bitsharesbase.operations import Transfer from bitshares.transactionbuilder import TransactionBuilder assert ctx.bitshares.rpc.chain_params[ "prefix"] == "TEST", "Flooding only on the testnet. Please switch the API to node testnet.bitshares.eu" account = Account(account, bitshares_instance=ctx.bitshares) to_account = Account(to, bitshares_instance=ctx.bitshares) tx = TransactionBuilder(bitshares_instance=ctx.bitshares) txcnt = 0 while txcnt < txs or txs < 0: txcnt += 1 for j in range(0, ops): tx.appendOps( Transfer( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "from": account["id"], "to": to_account["id"], "amount": { "amount": 1, "asset_id": "1.3.0" }, "memo": None })) tx.appendSigner(account, "active") tx.broadcast() click.echo(tx["signatures"])
def QReserveAsset(self, asset_id, amount_num, source_account, fee_asset=None, isolator=None): iso = isolator bitshares_instance = iso.bts tx = TransactionBuilder(bitshares_instance=bitshares_instance) src_account = iso.getAccount(source_account) params = { "amount_to_reserve": iso.getAmount(amount_num, asset_id).json(), "payer": iso.getAccount(source_account)['id'], } if fee_asset: params['fee'] = iso.getAmount(0, fee_asset).json() else: params['fee'] = {"amount": 0, "asset_id": "1.3.0"} from pprint import pprint print("USE:") pprint(params) tx.appendOps(Asset_reserve(**params)) if iso.bts.wallet.locked(): tx.addSigningInformation(src_account, "active", lazy=True) else: tx.appendSigner(src_account, "active", lazy=True) win = QTransactionBuilder(trxbuffer=tx, iso=isolator) return win.exec_()
def obtain_raw_tx(): # if old_operation is None: _memo = memo.encrypt(memo_plain) _expiration = Config.get("bitshares", "transaction_expiration_in_sec", 60 * 60 * 24) # 24 hours # else: # memo_encrypted = memo.encrypt(memo_plain) op = operations.Transfer(**{ "fee": { "amount": 0, "asset_id": "1.3.0" }, # will be replaced "from": from_account["id"], "to": to_account["id"], "amount": amount.json(), "memo": _memo, "prefix": bitshares_instance.prefix }) tx = TransactionBuilder( bitshares_instance=bitshares_instance ) tx.appendOps(op) tx.set_expiration(_expiration) # Build the transaction, obtain fee to be paid tx.constructTx() return tx.json()
def _QExecS(self, iso, vs): tx = TransactionBuilder(blockchain_instance=iso.bts) for (op, sigs) in vs: tx.appendOps(op) for (account, role) in sigs: if iso.bts.wallet.locked(): tx.addSigningInformation(account, role, lazy=True) else: tx.appendSigner(account, role, lazy=True) win = QTransactionBuilder(trxbuffer=tx, iso=iso) return win.exec_()
def QCreateWorker(self, worker_account, name, url, begin_date, end_date, daily_pay, worker_type, vesting_days=365, fee_asset=None, isolator=None): iso = isolator blockchain_instance = iso.bts tx = TransactionBuilder(blockchain_instance=blockchain_instance) src_account = iso.getAccount(worker_account) if isinstance(daily_pay, float): daily_pay = int(daily_pay * 100000) if worker_type == "vesting" or worker_type == 1: work_init = (1, {"pay_vesting_period_days": vesting_days}) elif worker_type == "burn" or worker_type == 2: work_init = (2, None) elif worker_type == "refund" or worker_type == 0: work_init = (0, None) else: raise ValueError("Unknown worker_type") params = { "owner": src_account['id'], "name": name, "url": url, "work_begin_date": begin_date.strftime("%Y-%m-%dT%H:%M:%S"), "work_end_date": end_date.strftime("%Y-%m-%dT%H:%M:%S"), "daily_pay": daily_pay, "initializer": work_init } if fee_asset: params['fee'] = iso.getAmount(0, fee_asset).json() else: params['fee'] = {"amount": 0, "asset_id": "1.3.0"} from pprint import pprint print("USE:") pprint(params) tx.appendOps(Worker_create(**params)) if iso.bts.wallet.locked(): tx.addSigningInformation(src_account, "active", lazy=True) else: tx.appendSigner(src_account, "active", lazy=True) win = QTransactionBuilder(trxbuffer=tx, iso=isolator) return win.exec_()
def QTransferToBlind(self, asset_id, amount_num, source_account, target_pubkey, fee_asset=None, isolator=None): iso = isolator blockchain_instance = iso.bts tx = TransactionBuilder(blockchain_instance=blockchain_instance) src_account = iso.getAccount(source_account) asset = iso.getAsset(asset_id) amount = iso.getAmount(amount_num, asset_id).json() from bitshares.blind import gen_blind_outputs confirm, balances = gen_blind_outputs( [[target_pubkey, amount["amount"]]], asset["id"] #,debug_priv="5JG5w3hXMq1fb32hzzd3CSWj4EMXeX6tiN2yxJf6SYZ8eZJ4EBB" ) params = { "amount": confirm["amount"], "from": src_account['id'], "blinding_factor": confirm["blinding_factor"], "outputs": confirm["outputs"], } if fee_asset: params['fee'] = iso.getAmount(0, fee_asset).json() else: params['fee'] = {"amount": 0, "asset_id": "1.3.0"} from pprint import pprint print("USE:") pprint(params) tx.appendOps(Transfer_to_blind(**params)) if iso.bts.wallet.locked(): tx.addSigningInformation(src_account, "active", lazy=True) else: tx.appendSigner(src_account, "active", lazy=True) win = QTransactionBuilder(trxbuffer=tx, iso=isolator) r = win.exec_() if not r: return False for b in balances: b["description"] = "from @" + src_account["name"] win._receiveBlindTransfers(iso, balances, [], comment1="@" + src_account["name"]) return True
def QIssueAsset(self, asset_id, amount_num, source_account, target_account, memo=None, fee_asset=None, isolator=None): iso = isolator blockchain_instance = iso.bts tx = TransactionBuilder(blockchain_instance=blockchain_instance) src_account = iso.getAccount(source_account) params = { "asset_to_issue": iso.getAmount(amount_num, asset_id).json(), "issuer": iso.getAccount(source_account)['id'], "issue_to_account": iso.getAccount(target_account)['id'], } if fee_asset: params['fee'] = iso.getAmount(0, fee_asset).json() else: params['fee'] = {"amount": 0, "asset_id": "1.3.0"} if memo: params['memo'] = iso.getMemo(source_account, target_account, memo) from pprint import pprint print("USE:") pprint(params) tx.appendOps(Asset_issue(**params)) if iso.bts.wallet.locked(): tx.addSigningInformation(src_account, "active", lazy=True) else: tx.appendSigner(src_account, "active", lazy=True) win = QTransactionBuilder(trxbuffer=tx, iso=isolator) return win.exec_()
def QCreateAsset(self, issuer, symbol, precision, max_supply, permissions={}, flags={}, description="", market_fee_percent=0, core_exchange_rate=None, is_prediction_market=False, bitasset_options=None, fee_asset=None, isolator=None): iso = isolator blockchain_instance = iso.bts tx = TransactionBuilder(blockchain_instance=blockchain_instance) src_account = iso.getAccount(issuer) permissions_int = toint(permissions) flags_int = toint(flags) #max_supply = total * pow(10, precision) #print("TOTAL:", total, "=> MAX SUPPLY:", max_supply) options = { "max_supply": max_supply, #satoshi "market_fee_percent": market_fee_percent, #0-100 "max_market_fee": max_supply, # satoshi "issuer_permissions": permissions_int, "flags": flags_int, "core_exchange_rate": { "base": { "amount": 1 * 100000, "asset_id": "1.3.0" }, "quote": { "amount": 1 * pow(10, precision), "asset_id": "1.3.1" } }, "whitelist_authorities": [], "blacklist_authorities": [], "whitelist_markets": [], "blacklist_markets": [], "description": description, "extensions": [], } if core_exchange_rate: core_exchange_rate["quote"]["asset_id"] = "1.3.1" options["core_exchange_rate"] = core_exchange_rate #bitasset_options = { # "feed_lifetime_sec": 86400, # "minimum_feeds": 1, # "force_settlement_delay_sec": 86400, # "force_settlement_offset_percent": 0, # "maximum_force_settlement_volume": 2000, # "short_backing_asset": "1.3.0" # "extensions": [] #} bitasset_options = { "feed_lifetime_sec": bitasset_options["feed_lifetime_sec"], "minimum_feeds": bitasset_options["minimum_feeds"], "force_settlement_delay_sec": bitasset_options["force_settlement_delay_sec"], "force_settlement_offset_percent": bitasset_options["force_settlement_offset_percent"], "maximum_force_settlement_volume": bitasset_options["maximum_force_settlement_volume"], "short_backing_asset": bitasset_options["short_backing_asset"], "extensions": [] } if bitasset_options else None params = { "issuer": src_account['id'], "symbol": symbol, "precision": precision, "common_options": options, "bitasset_opts": bitasset_options, "is_prediction_market": False, } if bitasset_options: params["is_prediction_market"] = False if fee_asset: params['fee'] = iso.getAmount(0, fee_asset).json() else: params['fee'] = {"amount": 0, "asset_id": "1.3.0"} from pprint import pprint print("USE:") pprint(params) tx.appendOps(Asset_create(**params)) if iso.bts.wallet.locked(): tx.addSigningInformation(src_account, "active", lazy=True) else: tx.appendSigner(src_account, "active", lazy=True) win = QTransactionBuilder(trxbuffer=tx, iso=isolator) return win.exec_()
def QRegisterAccount(self, registrar_name, referrer_name, data, fee_asset=None, isolator=None): iso = isolator blockchain_instance = iso.bts tx = TransactionBuilder(blockchain_instance=blockchain_instance) registrarAccount = iso.getAccount(registrar_name) referrerAccount = iso.getAccount(referrer_name) if not (registrarAccount.is_ltm): showerror("%s is not a lifetime member" % registrar_name) return None params = { "registrar": registrarAccount['id'], "referrer": referrerAccount['id'], "referrer_percent": 100, "name": data['name'], "owner": { 'account_auths': [], 'address_auths': [], 'weight_threshold': 1, 'key_auths': [[data['owner_key'], 1]] }, "active": { 'account_auths': [], 'address_auths': [], 'weight_threshold': 1, 'key_auths': [[data['active_key'], 1]] }, "options": { "memo_key": data['memo_key'], "votes": [], "voting_account": registrarAccount['id'], "num_witness": 0, "num_committee": 0, }, "extensions": [] } if fee_asset: params['fee'] = iso.getAmount(0, fee_asset).json() else: params['fee'] = {"amount": 0, "asset_id": "1.3.0"} #from pprint import pprint #print("USE:") #pprint(params) tx.appendOps(Account_create(**params)) if iso.bts.wallet.locked(): tx.addSigningInformation(registrarAccount, "active", lazy=True) else: tx.appendSigner(registrarAccount, "active", lazy=True) win = QTransactionBuilder(trxbuffer=tx, iso=isolator) return win.exec_()