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.crea.is_connected() and self.crea.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.crea.prefix)])

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

        super(TransactionBuilder, self).update(self.tx.json())
        self._unset_require_reconstruction()
Example #2
0
 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")
 def list_operations(self):
     """List all ops"""
     if self.crea.is_connected() and self.crea.rpc.get_use_appbase():
         # appbase disabled by now
         appbase = not self._use_condenser_api
     else:
         appbase = False
     return [
         Operation(o, appbase=appbase, prefix=self.crea.prefix)
         for o in self.ops
     ]
Example #4
0
 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
    def test_Transfer(self):
        transferJson = {
            'from': 'test',
            'to': 'test1',
            'amount': "1.000 CREA",
            '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="CREAAPPBASE")
        self.assertEqual(s.json()["operations"][0][1], transferJson)
Example #6
0
 def get_tx_size(self, op):
     """Returns the tx size of an operation"""
     ops = [Operation(op)]
     prefix = u"CREA"
     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
 def test_Operation(self):
     a = {"amount": '1000', "precision": 3, "nai": '@@000000013'}
     j = ["transfer", {'from': 'a', 'to': 'b', 'amount': a, 'memo': 'c'}]
     o = Operation(j)
     self.assertEqual(o.json()[1], j[1])