Beispiel #1
0
 def test_payload_fee(self):
     tx = MinterSendCoinTx(
         **{
             'nonce': 1,
             'chain_id': MinterTx.TESTNET_CHAIN_ID,
             'gas_coin': 'MNT',
             'to': self.TO,
             'coin': 'MNT',
             'value': 1,
             'payload': self.TX_PAYLOAD_UTF
         })
     tx.sign(self.PRIVATE_KEY)
     actual_fee = tx.get_fee()
     self.assertEqual(self.EXPECTED_SEND_COIN_FEE, actual_fee)
Beispiel #2
0
    def send(self, to, value, coin="BIP", payload='', include_commission=True):
        value = Decimal(str(value))

        nonce = self.API.get_nonce(self.address)
        tx = MinterSendCoinTx(coin=coin,
                              to=to,
                              value=value,
                              nonce=nonce,
                              gas_coin=coin,
                              payload=payload)

        if include_commission:
            if coin == 'BIP':
                commission = to_bip(tx.get_fee())
            else:
                tx.sign(self.private_key)
                commission = self.API.estimate_tx_commission(
                    tx.signed_tx, pip2bip=True)['result']['commission']

            tx.value = value - commission

        # Проверяем на ошибки
        if tx.value <= 0:
            print(
                f'Ошибка: Комиссия ({to_bip(tx.get_fee())}) превышает сумму выплаты ({value})'
            )
            return
        elif tx.value > self.get_balance(in_bip=True)[coin]:
            print(f'Ошибка: На кошельке недостаточно {coin}')
            return

        tx.sign(private_key=self.private_key)

        r = self.API.send_transaction(tx.signed_tx)

        try:
            if r['result']['code'] == 0:
                print(f'{value} {coin} успешно отпрвлены на адрес {to}')
                self._wait_for_nonce(
                    nonce
                )  # Ждем nonce, чтобы предотвратить отправку нескольких транзакций в блоке
        except Exception:
            print(f'Не удалось отправить {coin}\nServer response: {r}')

        return r