mirror of
https://github.com/basicswap/basicswap.git
synced 2024-11-17 00:07:56 +00:00
Fix wallet headings, loading existing smsges and amount compare precision.
This commit is contained in:
parent
1da0d06ef0
commit
ef77a9e012
4 changed files with 40 additions and 9 deletions
|
@ -31,6 +31,7 @@ from .util import (
|
|||
decodeWif,
|
||||
toWIF,
|
||||
getKeyID,
|
||||
makeInt,
|
||||
)
|
||||
from .chainparams import (
|
||||
chainparams,
|
||||
|
@ -554,6 +555,7 @@ class BasicSwap():
|
|||
ro = self.callrpc('smsginbox', ['unread', '', options])
|
||||
nm = 0
|
||||
for msg in ro['messages']:
|
||||
msg['hex'] += '00' # Add nullbtye to match output from 'smsg' cmd - TODO: make consistent
|
||||
self.processMsg(msg)
|
||||
nm += 1
|
||||
self.log.info('Scanned %d unread messages.', nm)
|
||||
|
@ -1580,7 +1582,7 @@ class BasicSwap():
|
|||
continue
|
||||
# Verify amount
|
||||
if assert_amount:
|
||||
assert(int(o['amount'] * COIN) == int(assert_amount)), 'Incorrect output amount in txn {}.'.format(assert_txid)
|
||||
assert(makeInt(o['amount']) == int(assert_amount)), 'Incorrect output amount in txn {}: {} != {}.'.format(assert_txid, makeInt(o['amount']), int(assert_amount))
|
||||
|
||||
if not sum_output:
|
||||
if o['height'] > 0:
|
||||
|
@ -1623,7 +1625,9 @@ class BasicSwap():
|
|||
initiate_txn = self.callcoinrpc(coin_from, 'getrawtransaction', [initiate_txnid_hex, True])
|
||||
# Verify amount
|
||||
vout = getVoutByAddress(initiate_txn, p2sh)
|
||||
assert(int(initiate_txn['vout'][vout]['value'] * COIN) == int(bid.amount)), 'Incorrect output amount in initiate txn.'
|
||||
|
||||
out_value = makeInt(initiate_txn['vout'][vout]['value'])
|
||||
assert(out_value == int(bid.amount)), 'Incorrect output amount in initiate txn {}: {} != {}.'.format(initiate_txnid_hex, out_value, int(bid.amount))
|
||||
|
||||
bid.initiate_tx.conf = initiate_txn['confirmations']
|
||||
try:
|
||||
|
@ -2122,6 +2126,7 @@ class BasicSwap():
|
|||
self.swaps_in_progress[bid_id] = (bid, offer)
|
||||
|
||||
def processMsg(self, msg):
|
||||
self.log.debug('processMsg %s', msg['hex'])
|
||||
self.mxDB.acquire()
|
||||
try:
|
||||
msg_type = int(msg['hex'][:2], 16)
|
||||
|
|
|
@ -219,6 +219,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||
tx_vsize = swap_client.getContractSpendTxVSize(k)
|
||||
est_fee = (fee_rate * tx_vsize) / 1000
|
||||
wallets_formatted.append({
|
||||
'name': w['name'],
|
||||
'cid': str(int(k)),
|
||||
'fee_rate': format8(fee_rate * COIN),
|
||||
'est_fee': format8(est_fee * COIN),
|
||||
|
|
|
@ -18,6 +18,11 @@ from xmlrpc.client import (
|
|||
from .segwit_addr import bech32_decode, convertbits, bech32_encode
|
||||
|
||||
COIN = 100000000
|
||||
DCOIN = decimal.Decimal(COIN)
|
||||
|
||||
|
||||
def makeInt(v):
|
||||
return int(dquantize(decimal.Decimal(v) * DCOIN).quantize(decimal.Decimal(1)))
|
||||
|
||||
|
||||
def format8(i):
|
||||
|
|
|
@ -9,6 +9,8 @@ import unittest
|
|||
from basicswap.util import (
|
||||
SerialiseNum,
|
||||
DeserialiseNum,
|
||||
makeInt,
|
||||
format8,
|
||||
)
|
||||
from basicswap.basicswap import (
|
||||
Coins,
|
||||
|
@ -19,15 +21,13 @@ from basicswap.basicswap import (
|
|||
)
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
def test_serialise_num(self):
|
||||
def test_case(v, nb=None):
|
||||
b = SerialiseNum(v)
|
||||
if nb is not None:
|
||||
assert(len(b) == nb)
|
||||
assert(v == DeserialiseNum(b))
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
def test_serialise_num(self):
|
||||
test_case(0, 1)
|
||||
test_case(1, 1)
|
||||
test_case(16, 1)
|
||||
|
@ -57,6 +57,26 @@ class Test(unittest.TestCase):
|
|||
decoded = decodeSequence(encoded)
|
||||
assert(decoded == blocks_val)
|
||||
|
||||
def test_makeInt(self):
|
||||
def test_case(v):
|
||||
sv = format8(makeInt(v))
|
||||
# Strip
|
||||
for i in range(7):
|
||||
if sv[-1] == '0':
|
||||
sv = sv[:-1]
|
||||
assert(sv == v)
|
||||
test_case('0.00899999')
|
||||
test_case('899999.0')
|
||||
test_case('899999.00899999')
|
||||
test_case('1.0')
|
||||
test_case('1.1')
|
||||
test_case('1.2')
|
||||
test_case('0.00899991')
|
||||
test_case('0.0089999')
|
||||
test_case('0.0089991')
|
||||
test_case('0.123')
|
||||
test_case('123000.000123')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in a new issue