Exemple #1
0
    def test_transfer_2of2_simple(self):
        # Send a 2 of 2 transaction from elf which needs bhive4's cosign to send funds
        hive = self.bts
        hive.nobroadcast = False
        tx = TransactionBuilder(use_condenser_api=True, hive_instance=hive)
        tx.appendOps(Transfer(**{"from": 'bhive5',
                                 "to": 'bhive1',
                                 "amount": Amount("0.01 HIVE", hive_instance=hive),
                                 "memo": '2 of 2 simple transaction'}))

        tx.appendWif(self.active_private_key_of_bhive5)
        tx.sign()
        tx.clearWifs()
        tx.appendWif(self.active_private_key_of_bhive4)
        tx.sign(reconstruct_tx=False)
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        hive.nobroadcast = True
Exemple #2
0
 def test_transfer_1of1(self):
     hive = self.bts
     hive.nobroadcast = False
     tx = TransactionBuilder(use_condenser_api=True, hive_instance=hive)
     tx.appendOps(Transfer(**{"from": 'bhive',
                              "to": 'bhive1',
                              "amount": Amount("0.01 HIVE", hive_instance=hive),
                              "memo": '1 of 1 transaction'}))
     self.assertEqual(
         tx["operations"][0]["type"],
         "transfer_operation"
     )
     tx.appendWif(self.active_key)
     tx.sign()
     tx.sign()
     self.assertEqual(len(tx['signatures']), 1)
     tx.broadcast()
     hive.nobroadcast = True
Exemple #3
0
 def test_verifyAuthorityException(self):
     nodelist = NodeList()
     hv = Hive(node=self.nodes,
                 keys=[self.posting_key],
                 nobroadcast=True,
                 expiration=120,
                 num_retries=10)
     tx = TransactionBuilder(use_condenser_api=True, hive_instance=hv)
     tx.appendOps(Transfer(**{"from": "bhive",
                              "to": "bhive1",
                              "amount": Amount("1 HIVE", hive_instance=hv),
                              "memo": ""}))
     account = Account("bhive2", hive_instance=hv)
     tx.appendSigner(account, "active")
     tx.appendWif(self.posting_key)
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     with self.assertRaises(
         exceptions.MissingRequiredActiveAuthority
     ):
         tx.verify_authority()
     self.assertTrue(len(tx["signatures"]) > 0)
Exemple #4
0
 def test_appendWif(self):
     nodelist = NodeList()
     hv = Hive(node=self.nodes,
                 nobroadcast=True,
                 expiration=120,
                 num_retries=10)
     tx = TransactionBuilder(use_condenser_api=True, hive_instance=hv)
     tx.appendOps(Transfer(**{"from": "bhive",
                              "to": "bhive1",
                              "amount": Amount("1 HIVE", hive_instance=hv),
                              "memo": ""}))
     with self.assertRaises(
         MissingKeyError
     ):
         tx.sign()
     with self.assertRaises(
         InvalidWifError
     ):
         tx.appendWif("abcdefg")
     tx.appendWif(self.active_key)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
Exemple #5
0
def test_post(wls):
    op1 = operations.Social_action(
        **{
            "account": "guest123",
            "social_action_comment_create": {
                "permlink": 'just-a-test-post',
                "parent_author": "",
                "parent_permlink": "test",
                "title": "just a test post",
                "body": "test post body",
                "json_metadata": '{"app":"wls_python"}'
            }
        })

    op2 = operations.Social_action(
        **{
            "account": "guest123",
            "social_action_comment_update": {
                "permlink": 'just-a-test-post',
                "title": "just a test post",
                "body": "test post body",
            }
        })

    op3 = operations.Vote(
        **{
            'voter': 'guest123',
            'author': 'wlsuser',
            'permlink': 'another-test-post',
            'weight': 10000,
        })

    privateWif = "5K..."
    tx = TransactionBuilder(use_condenser_api=True, hive_instance=wls)
    tx.appendOps(op1)
    tx.appendWif(privateWif)
    tx.sign()
    tx.broadcast()
Exemple #6
0
from bhive.nodelist import NodeList
from bhivebase.transactions import getBlockParams
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

# example wif
wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"

if __name__ == "__main__":
    hv_online = Hive()
    ref_block_num, ref_block_prefix = getBlockParams(hv_online)
    print("ref_block_num %d - ref_block_prefix %d" %
          (ref_block_num, ref_block_prefix))

    hv = Hive(offline=True)

    op = operations.Transfer({
        'from': 'bhive.app',
        'to': 'thecrazygm',
        'amount': "0.001 HBD",
        'memo': ""
    })
    tb = TransactionBuilder(hive_instance=hv)

    tb.appendOps([op])
    tb.appendWif(wif)
    tb.constructTx(ref_block_num=ref_block_num,
                   ref_block_prefix=ref_block_prefix)
    tx = tb.sign(reconstruct_tx=False)
    print(tx.json())