def test_finalizeOps(self): bts = self.bts tx1 = bts.new_tx() tx2 = bts.new_tx() acc = Account("bhive", hive_instance=bts) acc.transfer("bhive1", 1, "HIVE", append_to=tx1) acc.transfer("bhive1", 2, "HIVE", append_to=tx2) acc.transfer("bhive1", 3, "HIVE", append_to=tx1) tx1 = tx1.json() tx2 = tx2.json() ops1 = tx1["operations"] ops2 = tx2["operations"] self.assertEqual(len(ops1), 2) self.assertEqual(len(ops2), 1)
def test_transfer(self): bts = self.bts bts.nobroadcast = False bts.wallet.unlock("123") # bts.wallet.addPrivateKey(self.active_key) # bts.prefix ="STX" acc = Account("bhive", hive_instance=bts) tx = acc.transfer( "bhive1", 1.33, "HBD", memo="Foobar") self.assertEqual( tx["operations"][0][0], "transfer" ) self.assertEqual(len(tx['signatures']), 1) op = tx["operations"][0][1] self.assertIn("memo", op) self.assertEqual(op["from"], "bhive") self.assertEqual(op["to"], "bhive1") amount = Amount(op["amount"], hive_instance=bts) self.assertEqual(float(amount), 1.33) bts.nobroadcast = True
def test_transfer_memo(self): bts = self.bts bts.nobroadcast = False bts.wallet.unlock("123") acc = Account("bhive", hive_instance=bts) tx = acc.transfer( "bhive1", 1.33, "HBD", memo="#Foobar") self.assertEqual( tx["operations"][0][0], "transfer" ) op = tx["operations"][0][1] self.assertIn("memo", op) self.assertIn("#", op["memo"]) m = Memo(from_account=op["from"], to_account=op["to"], hive_instance=bts) memo = m.decrypt(op["memo"]) self.assertEqual(memo, "Foobar") self.assertEqual(op["from"], "bhive") self.assertEqual(op["to"], "bhive1") amount = Amount(op["amount"], hive_instance=bts) self.assertEqual(float(amount), 1.33) bts.nobroadcast = True
if useWallet: hv.wallet.addPrivateKey(owner_privkey) hv.wallet.addPrivateKey(active_privkey) hv.wallet.addPrivateKey(memo_privkey) hv.wallet.addPrivateKey(posting_privkey) else: hv = Hive(node=testnet_node, wif={ 'active': str(active_privkey), 'posting': str(posting_privkey), 'memo': str(memo_privkey) }) account = Account(username, hive_instance=hv) if account["name"] == "bhive": account.disallow("bhive1", permission='posting') account.allow('bhive1', weight=1, permission='posting', account=None) account.follow("bhive1") elif account["name"] == "bhive5": account.allow('bhive4', weight=2, permission='active', account=None) if useWallet: hv.wallet.getAccountFromPrivateKey(str(active_privkey)) # hv.create_account("bhive1", creator=account, password=password1) account1 = Account("bhive1", hive_instance=hv) b = Blockchain(hive_instance=hv) blocknum = b.get_current_block().identifier account.transfer("bhive1", 1, "HBD", "test") b1 = Block(blocknum, hive_instance=hv)
from __future__ import print_function from __future__ import unicode_literals import sys from datetime import datetime, timedelta import time import io import logging from bhive.blockchain import Blockchain from bhive.block import Block from bhive.account import Account from bhive.amount import Amount from bhivegraphenebase.account import PasswordKey, PrivateKey, PublicKey from bhive.hive import Hive from bhive.utils import parse_time, formatTimedelta from bhiveapi.exceptions import NumRetriesReached from bhive.nodelist import NodeList log = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) if __name__ == "__main__": # hv = Hive(node="https://testnet.timcliff.com/") # hv = Hive(node="https://testnet.hiveitdev.com") hv = Hive(node="https://api.hive.blog") hv.wallet.unlock(pwd="pwd123") account = Account("bhive.app", hive_instance=hv) print(account.get_voting_power()) account.transfer("thecrazygm", 0.001, "HBD", "test")