Exemple #1
0
    def test_transfer_2of2_serialized_deserialized(self):
        # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send
        # funds but sign the transaction with elf's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with steemfiles's key.
        steem = self.bts
        steem.nobroadcast = False
        steem.wallet.unlock("123")
        steem.wallet.removeAccount("steemfiles")

        tx = TransactionBuilder(steem_instance=steem)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'elf',
                    "to": 'leprechaun',
                    "amount": '0.01 SBD',
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

        tx.appendSigner("elf", "active")
        tx.addSigningInformation("elf", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        steem.wallet.removeAccount("elf")
        tx_json = tx.json()
        del tx
        new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem)
        self.assertEqual(len(new_tx['signatures']), 1)
        steem.wallet.addPrivateKey(self.active_private_key_of_steemfiles)
        new_tx.appendMissingSignatures()
        new_tx.sign(reconstruct_tx=False)
        self.assertEqual(len(new_tx['signatures']), 2)
        new_tx.broadcast()
        steem.nobroadcast = True
Exemple #2
0
    def test_transfer_2of2_offline(self):
        # Send a 2 of 2 transaction from beem5 which needs beem4's cosign to send
        # funds but sign the transaction with beem5's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with beem4's key.
        steem = self.bts
        steem.nobroadcast = False
        steem.wallet.unlock("123")
        steem.wallet.removeAccount("beem4")

        tx = TransactionBuilder(steem_instance=steem)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'beem5',
                    "to": 'beem',
                    "amount": '0.01 SBD',
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

        tx.appendSigner("beem5", "active")
        tx.addSigningInformation("beem5", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        steem.wallet.removeAccount("beem5")
        steem.wallet.addPrivateKey(self.active_private_key_of_beem4)
        tx.appendMissingSignatures()
        tx.sign(reconstruct_tx=False)
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        steem.nobroadcast = True
        steem.wallet.addPrivateKey(self.active_private_key_of_beem5)
Exemple #3
0
    def test_transfer_2of2_serialized_deserialized(self):
        # Send a 2 of 2 transaction from beem5 which needs beem4's cosign to send
        # funds but sign the transaction with beem5's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with beem4's key.
        steem = self.bts
        steem.nobroadcast = False
        steem.wallet.unlock("123")
        # steem.wallet.removeAccount("beem4")
        steem.wallet.removePrivateKeyFromPublicKey(str(PublicKey(self.active_private_key_of_beem4, prefix=core_unit)))

        tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem)
        tx.appendOps(Transfer(**{"from": 'beem5',
                                 "to": 'beem1',
                                 "amount": Amount("0.01 STEEM", steem_instance=steem),
                                 "memo": '2 of 2 serialized/deserialized transaction'}))

        tx.appendSigner("beem5", "active")
        tx.addSigningInformation("beem5", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        # steem.wallet.removeAccount("beem5")
        steem.wallet.removePrivateKeyFromPublicKey(str(PublicKey(self.active_private_key_of_beem5, prefix=core_unit)))
        tx_json = tx.json()
        del tx
        new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem)
        self.assertEqual(len(new_tx['signatures']), 1)
        steem.wallet.addPrivateKey(self.active_private_key_of_beem4)
        new_tx.appendMissingSignatures()
        new_tx.sign(reconstruct_tx=False)
        self.assertEqual(len(new_tx['signatures']), 2)
        new_tx.broadcast()
        steem.nobroadcast = True
Exemple #4
0
 def check_post(self):
     com = dict()
     com = {
         'parent_author': '',
         'parent_permlink': 'steem',
         'author': 'me',
         'permlink': 'testpost',
         'title': 'testpost pls ignore',
         'body': 'do not upvote',
         'json_metadata': {
             'tags': ('test', 'post', 'pls', 'ignore', 'steem'),
         }
     }
     print(len(com['body']))
     tx = TransactionBuilder(steem_instance=self.stm)
     tx.appendOps(Comment(com))
     tx.appendSigner("petertag", "active")
     signed_tx = tx.sign()
     sz = getsizeof(com)
     pprint(com)
     pprint(signed_tx)
     print("Size is %i" % sz)
     self.compute_cost(type=1,
                       tx_size=sz,
                       perm_len=len(com['permlink']),
                       pperm_len=len(com['parent_permlink']))
     broadcast_tx = tx.broadcast()
     pprint(broadcast_tx)
Exemple #5
0
    def test_transfer_2of2_wif(self):
        # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send
        # funds but sign the transaction with elf's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with steemfiles's key.
        steem = Steem(node=["wss://testnet.steem.vc"],
                      num_retries=10,
                      keys=[self.active_private_key_of_elf])

        tx = TransactionBuilder(steem_instance=steem)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'elf',
                    "to": 'leprechaun',
                    "amount": '0.01 SBD',
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

        tx.appendSigner("elf", "active")
        tx.addSigningInformation("elf", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        tx_json = tx.json()
        del steem
        del tx

        steem = Steem(node=["wss://testnet.steem.vc"],
                      num_retries=10,
                      keys=[self.active_private_key_of_steemfiles])
        new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem)
        new_tx.appendMissingSignatures()
        new_tx.sign(reconstruct_tx=False)
        self.assertEqual(len(new_tx['signatures']), 2)
        new_tx.broadcast()
Exemple #6
0
 def test_verifyAuthority(self):
     stm = self.bts
     stm.wallet.unlock("123")
     tx = TransactionBuilder(use_condenser_api=True, steem_instance=stm)
     tx.appendOps(Transfer(**{"from": "beem",
                              "to": "beem1",
                              "amount": Amount("1.300 SBD", steem_instance=stm),
                              "memo": "Foobar"}))
     account = Account("beem", steem_instance=stm)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     tx.verify_authority()
     self.assertTrue(len(tx["signatures"]) > 0)
Exemple #7
0
    def test_Transfer_broadcast(self):
        nodelist = NodeList()
        stm = Steem(node=self.nodes,
                    keys=[self.active_key],
                    nobroadcast=True,
                    expiration=120,
                    num_retries=10)

        tx = TransactionBuilder(use_condenser_api=True, expiration=10, steem_instance=stm)
        tx.appendOps(Transfer(**{"from": "beem",
                                 "to": "beem1",
                                 "amount": Amount("1 STEEM", steem_instance=stm),
                                 "memo": ""}))
        tx.appendSigner("beem", "active")
        tx.sign()
        tx.broadcast()
Exemple #8
0
 def test_Transfer_broadcast_appbase(self):
     stm = Steem(node=get_node_list(appbase=True),
                 keys=[wif],
                 num_retries=10)
     tx = TransactionBuilder(expiration=10, steem_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "test",
                 "to": "test1",
                 "amount": Amount("1 STEEM", steem_instance=stm),
                 "memo": ""
             }))
     tx.appendSigner("test", "active")
     tx.sign()
     with self.assertRaises(exceptions.MissingRequiredActiveAuthority):
         tx.broadcast()
Exemple #9
0
 def test_TransactionConstructor(self):
     stm = self.bts
     opTransfer = Transfer(**{"from": "beem",
                              "to": "beem1",
                              "amount": Amount("1 STEEM", steem_instance=stm),
                              "memo": ""})
     tx1 = TransactionBuilder(use_condenser_api=True, steem_instance=stm)
     tx1.appendOps(opTransfer)
     tx = TransactionBuilder(tx1, steem_instance=stm)
     self.assertFalse(tx.is_empty())
     self.assertTrue(len(tx.list_operations()) == 1)
     self.assertTrue(repr(tx) is not None)
     self.assertTrue(str(tx) is not None)
     account = Account("beem", steem_instance=stm)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
Exemple #10
0
    def test_transfer_2of2_wallet(self):
        # Send a 2 of 2 transaction from beem5 which needs beem4's cosign to send
        # priv key of beem5 and beem4 are stored in the wallet
        # appendSigner fetches both keys and signs automatically with both keys.
        steem = self.bts
        steem.nobroadcast = False
        steem.wallet.unlock("123")

        tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem)
        tx.appendOps(Transfer(**{"from": 'beem5',
                                 "to": 'beem1',
                                 "amount": Amount("0.01 STEEM", steem_instance=steem),
                                 "memo": '2 of 2 serialized/deserialized transaction'}))

        tx.appendSigner("beem5", "active")
        tx.sign()
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        steem.nobroadcast = True
Exemple #11
0
 def test_verifyAuthority_appbase(self):
     stm = self.appbase
     tx = TransactionBuilder(steem_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "test",
                 "to": "test1",
                 "amount": Amount("1 STEEM", steem_instance=stm),
                 "memo": ""
             }))
     account = Account("test", steem_instance=stm)
     tx.appendSigner(account, "active")
     tx.appendWif(wif)
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     with self.assertRaises(exceptions.MissingRequiredActiveAuthority):
         tx.verify_authority()
     self.assertTrue(len(tx["signatures"]) > 0)
Exemple #12
0
    def test_transfer_2of2_wif(self):
        nodelist = NodeList()
        # Send a 2 of 2 transaction from elf which needs beem4's cosign to send
        # funds but sign the transaction with elf's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with beem4's key.
        steem = Steem(
            node=self.nodes,
            num_retries=10,
            keys=[self.active_private_key_of_beem5],
            expiration=360,
        )

        tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'beem5',
                    "to": 'beem',
                    "amount": Amount("0.01 STEEM", steem_instance=steem),
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

        tx.appendSigner("beem5", "active")
        tx.addSigningInformation("beem5", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        tx_json = tx.json()
        del steem
        del tx

        steem = Steem(
            node=self.nodes,
            num_retries=10,
            keys=[self.active_private_key_of_beem4],
            expiration=360,
        )
        new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem)
        new_tx.appendMissingSignatures()
        new_tx.sign(reconstruct_tx=False)
        self.assertEqual(len(new_tx['signatures']), 2)
        new_tx.broadcast()
Exemple #13
0
 def test_appendSigner(self):
     nodelist = NodeList()
     stm = Steem(node=self.nodes,
                 keys=[self.active_key],
                 nobroadcast=True,
                 expiration=120,
                 num_retries=10)
     tx = TransactionBuilder(use_condenser_api=True, steem_instance=stm)
     tx.appendOps(Transfer(**{"from": "beem",
                              "to": "beem1",
                              "amount": Amount("1 STEEM", steem_instance=stm),
                              "memo": ""}))
     account = Account("beem", steem_instance=stm)
     with self.assertRaises(
         AssertionError
     ):
         tx.appendSigner(account, "abcdefg")
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
Exemple #14
0
 def test_appendSigner(self, node_param):
     if node_param == "non_appbase":
         stm = self.stm
     else:
         stm = self.appbase
     tx = TransactionBuilder(steem_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "test",
                 "to": "test1",
                 "amount": Amount("1 STEEM", steem_instance=stm),
                 "memo": ""
             }))
     account = Account("test", steem_instance=stm)
     with self.assertRaises(AssertionError):
         tx.appendSigner(account, "abcdefg")
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
Exemple #15
0
 def test_verifyAuthorityException(self):
     nodelist = NodeList()
     stm = Steem(node=self.nodes,
                 keys=[self.posting_key],
                 nobroadcast=True,
                 expiration=120,
                 num_retries=10)
     tx = TransactionBuilder(use_condenser_api=True, steem_instance=stm)
     tx.appendOps(Transfer(**{"from": "beem",
                              "to": "beem1",
                              "amount": Amount("1 STEEM", steem_instance=stm),
                              "memo": ""}))
     account = Account("beem2", steem_instance=stm)
     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 #16
0
    def test_transfer_2of2_wallet(self):
        # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send
        # priv key of elf and steemfiles are stored in the wallet
        # appendSigner fetches both keys and signs automatically with both keys.
        steem = self.bts
        steem.nobroadcast = False
        steem.wallet.unlock("123")

        tx = TransactionBuilder(steem_instance=steem)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'elf',
                    "to": 'leprechaun',
                    "amount": '0.01 SBD',
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

        tx.appendSigner("elf", "active")
        tx.sign()
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        steem.nobroadcast = True
Exemple #17
0
 def test_TransactionConstructor(self, node_param):
     if node_param == "non_appbase":
         stm = self.stm
     else:
         stm = self.appbase
     opTransfer = Transfer(
         **{
             "from": "test",
             "to": "test1",
             "amount": Amount("1 STEEM", steem_instance=stm),
             "memo": ""
         })
     tx1 = TransactionBuilder(steem_instance=stm)
     tx1.appendOps(opTransfer)
     tx = TransactionBuilder(tx1, steem_instance=stm)
     self.assertFalse(tx.is_empty())
     self.assertTrue(len(tx.list_operations()) == 1)
     self.assertTrue(repr(tx) is not None)
     self.assertTrue(str(tx) is not None)
     account = Account("test", steem_instance=stm)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
Exemple #18
0
        try:
            c.refresh()
        except ContentDoesNotExistsException:
            continue
        c_list[c.permlink] = 1
        if not c.is_comment():
            counter += 1
            if voter not in c.get_votes() and c.time_elapsed() > timedelta(
                    minutes=wait) and c.time_elapsed() < timedelta(hours=2):
                op = operations.Vote(
                    **{
                        "voter": voter,
                        "author": c.author,
                        "permlink": c.permlink,
                        "weight": int(percent * 100)
                    })
                ops = []
                ops.append(op)
                stm.wallet.unlock(wallet_pw)
                tx = TransactionBuilder(steem_instance=stm)
                tx.appendOps(ops)
                tx.appendSigner(signer, 'posting')
                tx.sign()
                returncode = tx.broadcast()
                print(returncode)
                voter_vp -= percent * 2 / 100
        if counter > 10 or voter_vp < min_vp or c.time_elapsed() > timedelta(
                hours=2):
            # going back 10 entries should be enough (50 minutes, on a spamming account e.g.)
            break
             "Total missed at or above threshold. Disabling witness server."
         )
         #Disable witness.
         tx = TransactionBuilder(steem_instance=stm)
         update_witness = {
             "owner": acct,
             "url": "No website yet",
             "block_signing_key":
             NATIVE_PREFIX + '1111111111111111111111111111111114T1Anm',
             "props": {
                 "account_creation_fee":
                 Amount("0.100 %s" % (NATIVE_SYMBOL)),
                 "maximum_block_size": 131072,
             },
             "fee": Amount("0.000 %s" % (NATIVE_SYMBOL)),
             "prefix": NATIVE_PREFIX,
         }
         op = operations.Witness_update(**update_witness)
         tx.appendOps(op)
         tx.appendSigner(acct, "active")
         #tx.appendWif(wif)
         signed_tx = tx.sign()
         broadcast_tx = tx.broadcast()
         pprint(broadcast_tx)
         exit()
     else:
         print("Witness server operational")
         print("--------------------------")
     time.sleep(60)  #Pause script for 60 seconds.
 except KeyboardInterrupt:
     exit()
Exemple #20
0
 for vote in vote_ops:
     
     print("broadcast voter %s votes %s" % (vote["voter"], vote["authorperm"]))
     author, permlink = resolve_authorperm(vote["authorperm"])
     op = operations.Vote(**{"voter": vote["voter"],
                             "author": author,
                             "permlink": permlink,
                             "weight": int(vote["weight"] * 100)})
     ops.append(op)      
     broadcasted_votes.append(vote)
     if len(ops) > 5:
         try:
             print("Broadcasting %d votes" % len(ops))
             tx.appendOps(ops)
             # tx.appendMissingSignatures()
             tx.appendSigner("rewarding", "posting")
             tx.sign()
             reply_message = tx.broadcast()
             # print(reply_message)
             ops = []
             #if vote["trail_vote"]:
             #    print("trail voter %s votes %s" % (vote["voter"], vote["authorperm"]))
             #else:
             #    print("voter %s votes %s after %.2f min (%.2f min)" % (vote["voter"], vote["authorperm"], age_min, vote["vote_delay_min"]))
             # reply_message = stm.vote(vote["weight"], vote["authorperm"], vote["voter"])
             # vote_count += 1
             expiration = formatTimeString(reply_message["expiration"]).replace(tzinfo=None)
         except Exception as e:
             expiration = datetime.utcnow()
             print("Vote failed: %s" % str(e))
             for vote in broadcasted_votes: