Ejemplo n.º 1
0
 def test_signing_appbase(self):
     b = Blockchain(steem_instance=self.bts)
     st = None
     for block in b.blocks(start=25304468, stop=25304468):
         for trx in block.transactions:
             st = Signed_Transaction(trx.copy())
     self.assertTrue(st is not None)
Ejemplo n.º 2
0
    def constructTx(self, ref_block_num=None, ref_block_prefix=None):
        """ Construct the actual transaction and store it in the class's dict
            store

        """
        ops = list()
        if self.steem.is_connected() and self.steem.rpc.get_use_appbase():
            # appbase disabled by now
            # broadcasting does not work at the moment
            appbase = not self._use_condenser_api
        else:
            appbase = False
        for op in self.ops:
            # otherwise, we simply wrap ops into Operations
            ops.extend(
                [Operation(op, appbase=appbase, prefix=self.steem.prefix)])

        # We no wrap everything into an actual transaction
        expiration = formatTimeFromNow(self.expiration
                                       or self.steem.expiration)
        if ref_block_num is None or ref_block_prefix is None:
            ref_block_num, ref_block_prefix = transactions.getBlockParams(
                self.steem.rpc)
        self.tx = Signed_Transaction(ref_block_prefix=ref_block_prefix,
                                     expiration=expiration,
                                     operations=ops,
                                     ref_block_num=ref_block_num,
                                     custom_chains=self.steem.custom_chains,
                                     prefix=self.steem.prefix)

        super(TransactionBuilder, self).update(self.tx.json())
        self._unset_require_reconstruction()
Ejemplo n.º 3
0
 def test_verify_transaction(self):
     stm = self.stm
     block = Block(22005665, steem_instance=stm)
     trx = block.transactions[28]
     signed_tx = Signed_Transaction(trx)
     key = signed_tx.verify(chain=stm.chain_params, recover_parameter=False)
     public_key = format(Base58(key[0]), stm.prefix)
     self.assertEqual(public_key, "STM4tzr1wjmuov9ftXR6QNv7qDWsbShMBPQpuwatZsfSc5pKjRDfq")
Ejemplo n.º 4
0
def get_signer(trx):
    try:
        st = Signed_Transaction(trx.copy())
    except Exception:
        return None

    keys = []
    for key in st.verify(recover_parameter=True):
        keys.append(format(Base58(key, prefix='STM'), 'STM'))
    return keys
 def doit(self, printWire=False, ops=None):
     if ops is None:
         ops = [Operation(self.op)]
     tx = Signed_Transaction(ref_block_num=self.ref_block_num,
                             ref_block_prefix=self.ref_block_prefix,
                             expiration=self.expiration,
                             operations=ops)
     tx = tx.sign([self.wif], chain=self.prefix)
     tx.verify([PrivateKey(self.wif, prefix=u"STM").pubkey], self.prefix)
     txWire = hexlify(py23_bytes(tx)).decode("ascii")
Ejemplo n.º 6
0
 def test_verify_transaction(self):
     stm = self.stm
     block = Block(22005665, steem_instance=stm)
     trx = block.transactions[28]
     signed_tx = Signed_Transaction(trx)
     key = signed_tx.verify(chain=stm.chain_params, recover_parameter=False)
     public_key = format(Base58(key[0]), stm.prefix)
     self.assertEqual(
         public_key,
         "STM4xA6aCu23rKxsEZWF2xVYJvJAyycuoFxBRQEuQ5Hc7UtFET7fT")
Ejemplo n.º 7
0
    def constructTx(self, ref_block_num=None, ref_block_prefix=None):
        """ Construct the actual transaction and store it in the class's dict
            store

        """
        ops = list()
        if self.blockchain.is_connected(
        ) and self.blockchain.rpc.get_use_appbase():
            # appbase disabled by now
            # broadcasting does not work at the moment
            appbase = not self._use_condenser_api
        else:
            appbase = False
        for op in self.ops:
            # otherwise, we simply wrap ops into Operations
            ops.extend([
                Operation(op, appbase=appbase, prefix=self.blockchain.prefix)
            ])

        # calculation expiration time from last block time not system time
        # it fixes transaction expiration error when pushing transactions
        # when blocks are moved forward with debug_produce_block*
        if self.blockchain.is_connected():
            now = formatTimeString(
                self.blockchain.get_dynamic_global_properties(
                    use_stored_data=False).get('time')).replace(tzinfo=None)
            expiration = now + timedelta(
                seconds=int(self.expiration or self.blockchain.expiration))
            expiration = expiration.replace(microsecond=0).isoformat()
        else:
            expiration = formatTimeFromNow(self.expiration
                                           or self.blockchain.expiration)

        # We now wrap everything into an actual transaction
        if ref_block_num is None or ref_block_prefix is None:
            ref_block_num, ref_block_prefix = self.get_block_params()
        if self._use_ledger:
            self.ledgertx = Ledger_Transaction(
                ref_block_prefix=ref_block_prefix,
                expiration=expiration,
                operations=ops,
                ref_block_num=ref_block_num,
                custom_chains=self.blockchain.custom_chains,
                prefix=self.blockchain.prefix)

        self.tx = Signed_Transaction(
            ref_block_prefix=ref_block_prefix,
            expiration=expiration,
            operations=ops,
            ref_block_num=ref_block_num,
            custom_chains=self.blockchain.custom_chains,
            prefix=self.blockchain.prefix)

        super(TransactionBuilder, self).update(self.tx.json())
        self._unset_require_reconstruction()
 def doit(self, printWire=False, ops=None):
     ops = [Operation(ops)]
     tx = Signed_Transaction(ref_block_num=self.ref_block_num,
                             ref_block_prefix=self.ref_block_prefix,
                             expiration=self.expiration,
                             operations=ops)
     start = timer()
     tx = tx.sign([self.wif], chain=self.prefix)
     end1 = timer()
     tx.verify([PrivateKey(self.wif, prefix=u"STM").pubkey], self.prefix)
     end2 = timer()
     return end2 - end1, end1 - start
Ejemplo n.º 9
0
    def sign(self, reconstruct_tx=True):
        """ Sign a provided transaction with the provided key(s)
            One or many wif keys to use for signing a transaction.
            The wif keys can be provided by "appendWif" or the
            signer can be defined "appendSigner". The wif keys
            from all signer that are defined by "appendSigner
            will be loaded from the wallet.

            :param bool reconstruct_tx: when set to False and tx
                is already contructed, it will not reconstructed
                and already added signatures remain

        """
        if not self._is_constructed() or (self._is_constructed()
                                          and reconstruct_tx):
            self.constructTx()
        if "operations" not in self or not self["operations"]:
            return
        if self.blockchain.use_sc2:
            return
        # We need to set the default prefix, otherwise pubkeys are
        # presented wrongly!
        if self.blockchain.rpc is not None:
            operations.default_prefix = (
                self.blockchain.chain_params["prefix"])
        elif "blockchain" in self:
            operations.default_prefix = self["blockchain"]["prefix"]

        if self._use_ledger:
            #try:
            #    ledgertx = Ledger_Transaction(**self.json(with_prefix=True))
            #    ledgertx.add_custom_chains(self.blockchain.custom_chains)
            #except:
            #    raise ValueError("Invalid TransactionBuilder Format")
            #ledgertx.sign(self.path, chain=self.blockchain.chain_params)
            self.ledgertx.sign(self.path, chain=self.blockchain.chain_params)
            self["signatures"].extend(self.ledgertx.json().get("signatures"))
            return self.ledgertx
        else:
            try:
                signedtx = Signed_Transaction(**self.json(with_prefix=True))
                signedtx.add_custom_chains(self.blockchain.custom_chains)
            except:
                raise ValueError("Invalid TransactionBuilder Format")

            if not any(self.wifs):
                raise MissingKeyError

            signedtx.sign(self.wifs, chain=self.blockchain.chain_params)
            self["signatures"].extend(signedtx.json().get("signatures"))
            return signedtx
Ejemplo n.º 10
0
Archivo: rc.py Proyecto: symbiotes/beem
 def get_tx_size(self, op):
     """Returns the tx size of an operation"""
     ops = [Operation(op)]
     prefix = u"STEEM"
     wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
     ref_block_num = 34294
     ref_block_prefix = 3707022213
     expiration = "2016-04-06T08:29:27"
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     tx = tx.sign([wif], chain=prefix)
     txWire = hexlify(py23_bytes(tx)).decode("ascii")
     tx_size = len(txWire)
     return tx_size
Ejemplo n.º 11
0
    def test_Transfer(self):
        transferJson = {
            'from': 'test',
            'to': 'test1',
            'amount': "1.000 STEEM",
            'memo': 'foobar'
        }
        t = Transfer(transferJson)
        self.assertEqual(transferJson, json.loads(str(t)))
        self.assertEqual(transferJson, t.json())
        self.assertEqual(transferJson, t.toJson())
        self.assertEqual(transferJson, t.__json__())

        transferJson = {
            'from': 'test',
            'to': 'test1',
            'amount': ['3000', 3, '@@000000037'],
            'memo': 'foobar'
        }
        t = Transfer(transferJson)
        self.assertEqual(transferJson, json.loads(str(t)))
        self.assertEqual(transferJson, t.json())
        self.assertEqual(transferJson, t.toJson())
        self.assertEqual(transferJson, t.__json__())

        o = Operation(Transfer(transferJson))
        self.assertEqual(o.json()[1], transferJson)
        tx = {
            'ref_block_num': 0,
            'ref_block_prefix': 0,
            'expiration': '2018-04-07T09:30:53',
            'operations': [o],
            'extensions': [],
            'signatures': []
        }
        s = Signed_Transaction(tx)
        s.sign(wifkeys=[wif], chain="STEEMAPPBASE")
        self.assertEqual(s.json()["operations"][0][1], transferJson)
Ejemplo n.º 12
0
    def constructTx(self):
        """ Construct the actual transaction and store it in the class's dict
            store

        """
        ops = list()
        for op in self.ops:
            # otherwise, we simply wrap ops into Operations
            ops.extend([Operation(op)])

        # We no wrap everything into an actual transaction
        # ops = transactions.addRequiredFees(self.steem.rpc, ops)
        expiration = formatTimeFromNow(self.expiration
                                       or self.steem.expiration)
        ref_block_num, ref_block_prefix = transactions.getBlockParams(
            self.steem.rpc)
        self.tx = Signed_Transaction(ref_block_prefix=ref_block_prefix,
                                     expiration=expiration,
                                     operations=ops,
                                     ref_block_num=ref_block_num)

        super(TransactionBuilder, self).update(self.tx.json())
        self._unset_require_reconstruction()
Ejemplo n.º 13
0
                                            ) and op["type"][:4] == "vote":
                                                if op["value"][
                                                        "voter"] == vote[
                                                            "voter"]:
                                                    transaction = tt
                                            elif isinstance(op, list) and len(
                                                    op
                                            ) > 1 and op[0][:4] == "vote":
                                                if op[1]["voter"] == vote[
                                                        "voter"]:
                                                    transaction = tt
                                    block_cnt += 1
                                vote_did_sign = True
                                key_accounts = []
                                if transaction is not None:
                                    signed_tx = Signed_Transaction(transaction)
                                    public_keys = []
                                    for key in signed_tx.verify(
                                            chain=stm.chain_params,
                                            recover_parameter=True):
                                        public_keys.append(
                                            format(
                                                Base58(key, prefix=stm.prefix),
                                                stm.prefix))

                                    empty_public_keys = []
                                    for key in public_keys:
                                        pubkey_account = wallet.getAccountFromPublicKey(
                                            key)
                                        if pubkey_account is None:
                                            empty_public_keys.append(key)