Skip to content

Commit

Permalink
SFT-2392: differentiated between testnet and mainnet for address
Browse files Browse the repository at this point in the history
searching
  • Loading branch information
mjg-foundation committed Aug 21, 2023
1 parent f92435c commit 65d1454
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 11 additions & 3 deletions ports/stm32/boards/Passport/modules/flows/verify_address_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ async def scan_address(self):
self.address = result

# Simple check on the data type first
chain_name = chains.current_chain().name
chain = chains.current_chain()
self.address, is_valid_btc = is_valid_btc_address(self.address)
if not is_valid_btc:
await ErrorPage("Not a valid {} address.".format(chain_name)).show()
await ErrorPage("Not a valid {} address.".format(chain.name)).show()
return

# Get the address type from the address
Expand All @@ -105,10 +105,12 @@ async def scan_address(self):
a = [get_next_addr(self.acct_num,
self.addr_type,
xfp,
chain.b44_cointype,
False),
get_next_addr(self.acct_num,
self.addr_type,
xfp,
chain.b44_cointype,
True)]
self.low_range = [(a[_RECEIVE_ADDR], a[_RECEIVE_ADDR]), (a[_CHANGE_ADDR], a[_CHANGE_ADDR])]
self.high_range = [(a[_RECEIVE_ADDR], a[_RECEIVE_ADDR]), (a[_CHANGE_ADDR], a[_CHANGE_ADDR])]
Expand Down Expand Up @@ -224,9 +226,15 @@ async def found(self):
from utils import save_next_addr, format_btc_address
import passport
from common import settings
import chains

# Remember where to start from next time
save_next_addr(self.acct_num, self.addr_type, self.found_addr_idx, settings.get('xfp'), self.found_is_change)
save_next_addr(self.acct_num,
self.addr_type,
self.found_addr_idx,
settings.get('xfp'),
chains.current_chain().b44_cointype,
self.found_is_change)
address = format_btc_address(self.address, self.addr_type)

msg = '''{}
Expand Down
12 changes: 6 additions & 6 deletions ports/stm32/boards/Passport/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,23 +949,23 @@ def get_width_from_num_words(num_words):
# return False


def make_next_addr_key(acct_num, addr_type, xfp, is_change):
return '{}.{}/{}{}'.format(xfp, acct_num, addr_type, '/1' if is_change else '')
def make_next_addr_key(acct_num, addr_type, xfp, chain_type, is_change):
return '{}.{}.{}/{}{}'.format(chain_type, xfp, acct_num, addr_type, '/1' if is_change else '')


def get_next_addr(acct_num, addr_type, xfp, is_change):
def get_next_addr(acct_num, addr_type, xfp, chain_type, is_change):
from common import settings
next_addrs = settings.get('next_addrs', {})
key = make_next_addr_key(acct_num, addr_type, xfp, is_change)
key = make_next_addr_key(acct_num, addr_type, xfp, chain_type, is_change)
return next_addrs.get(key, 0)

# Save the next address to use for the specific account and address type


def save_next_addr(acct_num, addr_type, addr_idx, xfp, is_change, force_update=False):
def save_next_addr(acct_num, addr_type, addr_idx, xfp, chain_type, is_change, force_update=False):
from common import settings
next_addrs = settings.get('next_addrs', {})
key = make_next_addr_key(acct_num, addr_type, xfp, is_change)
key = make_next_addr_key(acct_num, addr_type, xfp, chain_type, is_change)

# Only save the found index if it's newer
if next_addrs.get(key, -1) < addr_idx or force_update:
Expand Down

0 comments on commit 65d1454

Please sign in to comment.