commit 7c62a86cd6e5c62acb96f1628bedaebb8bc515cd
parent 3ecf81209f01297508238bcc390bf612bdd9828a
Author: lash <dev@holbrook.no>
Date: Mon, 13 Feb 2023 05:47:47 +0000
Enable setting unsigned sender in args, config
Diffstat:
5 files changed, 46 insertions(+), 10 deletions(-)
diff --git a/chainlib/cli/arg.py b/chainlib/cli/arg.py
@@ -1,10 +1,8 @@
# standard imports
import logging
import argparse #import enum
-#import os
import select
import sys
-#import re
# external imports
from aiee.arg import (
@@ -78,11 +76,13 @@ class ArgFlag(BaseArgFlag):
self.add('backend')
self.add('value')
self.add('tab')
+ self.add('sender')
self.alias('sign', 'key_file', 'send')
self.alias('std_base', 'verbose', 'config', 'raw', 'env', 'target')
self.alias('std_base_read', 'unsafe', 'verbose', 'config', 'raw', 'env', 'provider', 'chain_spec', 'seq')
- self.alias('std_read', 'std_base', 'provider', 'chain_spec', 'unsafe', 'seq', 'sign', 'fee', 'target')
+ self.alias('std_read', 'std_base', 'provider', 'chain_spec', 'unsafe', 'seq', 'fee', 'target', 'sign', 'sender')
+ self.alias('std_read_noex', 'std_base', 'provider', 'chain_spec', 'seq', 'target')
self.alias('std_write', 'verbose', 'config', 'raw', 'env', 'provider', 'chain_spec', 'unsafe', 'seq', 'key_file', 'sign', 'target', 'wait', 'wait_all', 'send', 'rpc_auth', 'nonce', 'fee')
self.alias('std_target', 'no_target', 'exec', 'wallet')
self.alias('state', 'backend', 'path')
@@ -139,6 +139,9 @@ class Arg(BaseArg):
self.add('s', 'send', typ=bool, help='Send to network')
self.set_long('s', 'send')
+ self.add('f', 'sender', type=str, help='Unsigned sender')
+ self.set_long('f', 'from')
+
self.add('r', 'raw', typ=bool, help='Do not decode output')
self.set_long('r', 'raw')
self.add('0', 'raw', typ=bool, help='Omit newline to output')
diff --git a/chainlib/cli/config.py b/chainlib/cli/config.py
@@ -103,10 +103,6 @@ def process_config(config, arg, args, flags, positional_name=None):
if arg.match('fee', flags):
config.add(getattr(args, 'fee_price'), '_FEE_PRICE')
- fee_limit = getattr(args, 'fee_limit')
- if fee_limit == None:
- fee_limit = int(config.get('CHAIN_MIN_FEE'))
- config.add(fee_limit, '_FEE_LIMIT')
if arg.match('nonce', flags):
config.add(getattr(args, 'nonce'), '_NONCE')
@@ -117,7 +113,13 @@ def process_config(config, arg, args, flags, positional_name=None):
config.add(True, '_WAIT')
elif args.w:
config.add(True, '_WAIT')
-
+
+ if arg.match('fee', flags):
+ fee_limit = getattr(args, 'fee_limit')
+ if fee_limit == None:
+ fee_limit = int(config.get('CHAIN_MIN_FEE'))
+ config.add(fee_limit, '_FEE_LIMIT')
+
if arg.match('seq', flags):
config.add(getattr(args, 'seq'), '_SEQ')
@@ -134,6 +136,9 @@ def process_config(config, arg, args, flags, positional_name=None):
config.add(getattr(args, 'rpc_auth'), 'RPC_AUTH')
config.add(getattr(args, 'rpc_credentials'), 'RPC_CREDENTIALS')
+ if arg.match('sender', flags):
+ config.add(getattr(args, 'f'), '_UNSIGNED_SENDER_ADDRESS')
+
if positional_name != None:
config.add(None, '_POSARG', False)
pos_arg = getattr(args, positional_name)
diff --git a/chainlib/cli/rpc.py b/chainlib/cli/rpc.py
@@ -20,6 +20,8 @@ class Rpc:
:param wallet: Add wallet backend to instance
:type wallet: chainlib.cli.wallet.Wallet
"""
+
+ default_sender_address = None
def __init__(self, cls, wallet=None):
self.constructor = cls
@@ -30,6 +32,7 @@ class Rpc:
self.nonce_oracle = None
self.fee_oracle = None
self.error_parser = None
+ self.sender_address = self.default_sender_address
def connect_by_config(self, config):
@@ -63,6 +66,17 @@ class Rpc:
self.chain_spec = config.get('CHAIN_SPEC')
self.conn = self.constructor(url=config.get('RPC_PROVIDER'), chain_spec=self.chain_spec, auth=auth, verify_identity=config.true('RPC_VERIFY'), timeout=float(config.get('RPC_TIMEOUT')))
+ if self.wallet.signer != None:
+ self.sender_address = self.wallet.signer_address
+ elif config.get('_UNSIGNED_SENDER_ADDRESS') != None:
+ try:
+ self.sender_address = config.get('_UNSIGNED_SENDER_ADDRESS')
+ except KeyError:
+ pass
+ except ValueError:
+ pass
+ logg.debug('default sender address {} {}'.format(self.default_sender_address, self.sender_address))
+
return self.conn
@@ -112,8 +126,10 @@ class Rpc:
:rtype: str
:returns: Wallet address in canonical string representation
"""
- return self.wallet.signer_address
+ return self.sender_address
def get_signer_address(self):
+ if self.wallet == None:
+ return None
return self.get_sender_address()
diff --git a/chainlib/settings.py b/chainlib/settings.py
@@ -1,9 +1,14 @@
+# standard imports
+import logging
+
# external imports
from aiee.numbers import postfix_to_int
# local imports
from .chain import ChainSpec
+logg = logging.getLogger(__name__)
+
class ChainSettings:
@@ -39,6 +44,12 @@ def process_settings_common(settings, config):
return settings
+def process_settings_signer_check(settings, config):
+ if config.get('WALLET_KEY_FILE') != None and config.get('_UNSIGNED_SENDER_ADDRESS') != None:
+ logg.warning('misconfigured client has both wallet key file and signed sender options set')
+ return settings
+
+
def process_settings_value(settings, config):
value = None
try:
@@ -56,4 +67,5 @@ def process_settings(settings, config):
settings = process_settings_common(settings, config)
settings = process_settings_value(settings, config)
settings = process_settings_dialect(settings, config)
+ settings = process_settings_signer_check(settings, config)
return settings
diff --git a/setup.cfg b/setup.cfg
@@ -3,7 +3,7 @@ name=chainlib
license=AGPLv3+
author_email=dev@holbrook.no
description=Generic blockchain access library and tooling
-version=0.4.6
+version=0.4.7
url=https://git.defalsify.org/chainlib
author=Louis Holbrook