added timeout

This commit is contained in:
blackmask 2023-03-29 05:04:04 +01:00
parent 55cd8d0d58
commit 15df24e296
6 changed files with 51 additions and 18 deletions

View File

@ -104,13 +104,13 @@ class MultisigWallet():
command.append(f'--{key}={value}')
elif isinstance(value, bool) and value:
command.append(f'--{key}')
self.process = Popen(command, stdout=PIPE, stdin=PIPE, stderr=STDOUT)
self.process = Popen(command)#, stdout=PIPE, stdin=PIPE, stderr=STDOUT)
self.auth = requests.auth.HTTPDigestAuth(self.name, self.password)
self.session = requests.Session()
self.url = f'http://127.0.0.1:{self.port}/json_rpc'
if wait:
i = 0
while i < 10:
while i < self.settings.get('timeout', 30):
i += 1
if self.test_command():
print('Connected...')
@ -136,7 +136,7 @@ class MultisigWallet():
headers={'Content-Type': 'application/json'},
data=json.dumps({'jsonrpc': '2.0', 'id': 0, 'method': 'get_version'}),
auth=self.auth,
timeout=30
timeout=self.settings.get('timeout', 30)
)
if resp.status_code == 200:
return True
@ -154,7 +154,7 @@ class MultisigWallet():
headers={'Content-Type': 'application/json'},
data=json.dumps({'jsonrpc': '2.0', 'id': 0, 'method': method, 'params': params or {}}),
auth=self.auth,
timeout=10
timeout=self.settings.get('timeout', 30)
)
if resp.status_code == 200:
self.is_blocked = False

View File

@ -53,6 +53,7 @@ class SettingsRPC(BaseRPC):
'stagenet': bool,
'testnet': bool,
'proxy': str,
'timeout': int,
}
def get(self, request):
@ -123,6 +124,15 @@ class WalletBaseRPC(BaseRPC):
return request.get_wallet(wallet_id)
class WalletPrepareRPC(WalletBaseRPC):
def get(self, request, wallet_id):
wallet = self.get_wallet(request, wallet_id)
wallet.rpc_stop()
wallet.turn_ms_on()
wallet.prepare_multisig()
return self.success(wallet.name)
class WalletDetailRPC(WalletBaseRPC):
def get(self, request, wallet_id):
wallet = self.get_wallet(request, wallet_id)

View File

@ -52,6 +52,12 @@
<input id="form-proxy" name="proxy" onChange="disableTest()" type="text">
</td>
</tr>
<tr>
<th>Timeout</th>
<td>
<input id="form-timeout" name="timeout" onChange="disableTest()" type="number">
</td>
</tr>
</table>
<button class="button" id="btn-settings-save" onClick="saveSettings()">Save</button>
<button class="button" id="btn-settings-test" onClick="testConnection()">Test</button>
@ -154,6 +160,7 @@
$('#form-stagenet').prop('checked', resp.stagenet);
$('#form-testnet').prop('checked', resp.testnet);
$('#form-proxy').val(resp.proxy);
$('#form-timeout').val(resp.timeout);
enableTest();
}
});
@ -172,6 +179,7 @@
'stagenet': $('#form-stagenet').prop('checked'),
'testnet': $('#form-testnet').prop('checked'),
'proxy': $('#form-proxy').val(),
'timeout': $('#form-timeout').val(),
}, function(resp, status) {
if (resp.errors) {
enableTest();

View File

@ -33,9 +33,13 @@
if (wal.state == 'finalized') text += 'Finalized';
else text += 'Making MS';
text += '</td><td class="centered">';
if (wal.key1) text += '<button class="button sm" onClick="showCopyText(\'' + wal.key1 + '\')"><i class="icon i-key"></i>1</button> ';
if (wal.key2) text += '<button class="button sm" onClick="showCopyText(\'' + wal.key2 + '\')"><i class="icon i-key"></i>2</button> ';
if (wal.key3) text += '<button class="button sm" onClick="showCopyText(\'' + wal.key3 + '\')"><i class="icon i-key"></i>3</button> ';
if (wal.key1) {
if (wal.key1) text += '<button class="button sm" onClick="showCopyText(\'' + wal.key1 + '\')"><i class="icon i-key"></i>1</button> ';
if (wal.key2) text += '<button class="button sm" onClick="showCopyText(\'' + wal.key2 + '\')"><i class="icon i-key"></i>2</button> ';
if (wal.key3) text += '<button class="button sm" onClick="showCopyText(\'' + wal.key3 + '\')"><i class="icon i-key"></i>3</button> ';
} else {
text += '<button class="button md" onClick="prepareWallet(\'' + wal.name + '\')">Prepare</button>';
}
text += '<td class="centered">' + wal.created_at + '</td></tr>';
}
} else {
@ -58,4 +62,15 @@
}
});
}
function prepareWallet(wallet_id) {
blockPage();
$.get('/rpc/wallets/' + wallet_id + '/prepare/', function(resp, status) {
if (resp.errors) showWalletError(resp.errors);
else {
unblockPage();
onLoad();
}
});
}
</script>

View File

@ -5,6 +5,7 @@ URLS = {
# RPC
'/rpc/settings/test/': rpc.SettingsTestRPC,
'/rpc/settings/': rpc.SettingsRPC,
'/rpc/wallets/(?P<wallet_id>[\d]+)/prepare/': rpc.WalletPrepareRPC,
'/rpc/wallets/(?P<wallet_id>[\d]+)/label/': rpc.WalletLabelRPC,
'/rpc/wallets/(?P<wallet_id>[\d]+)/balance/': rpc.WalletBalanceRPC,
'/rpc/wallets/(?P<wallet_id>[\d]+)/rescan/': rpc.WalletRescanRPC,

View File

@ -41,6 +41,7 @@ class XMSRequestHandler(BaseHTTPRequestHandler):
'stagenet': False,
'testnet': False,
'proxy': '',
'timeout': 30,
}
def __init__(self, *args, **kwargs):
@ -71,17 +72,15 @@ class XMSRequestHandler(BaseHTTPRequestHandler):
return
wallets = {}
for p in paths:
fn = os.path.join('wallets', p, 'ms.round1.txt')
if os.path.exists(fn):
key1 = open(fn).read().strip()
if key1:
wallet = {
'name': p,
'key1': key1,
}
wallet['created_at'] = datetime.fromtimestamp(
os.lstat(fn).st_ctime
).strftime('%Y-%m-%d %H:%M:%S')
wallet = {'name': p}
if os.path.exists(os.path.join('wallets', p, 'wallet.password.txt')):
fn = os.path.join('wallets', p, 'ms.round1.txt')
if os.path.exists(fn):
key1 = open(fn).read().strip()
wallet['key1'] = key1
wallet['created_at'] = datetime.fromtimestamp(
os.lstat(fn).st_ctime
).strftime('%Y-%m-%d %H:%M:%S')
items = {
'address': 'wallet.address.txt',
'label': 'wallet.label.txt',