From 858dea111f4c0f315d2919918f0112ff640821d4 Mon Sep 17 00:00:00 2001 From: Command Date: Sun, 15 Nov 2020 09:39:18 +0800 Subject: [PATCH] autofill convener --- CHANGELOG.md | 4 ++++ README.md | 6 +++--- bin/ngwallet.dart | 32 ++++++++++++++------------------ pubspec.yaml | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93c1c98..80f2caf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.2 + +- no need to input convener any longer, wallet will auto recognize + ## 0.1.1 - Shorten the commands diff --git a/README.md b/README.md index 39282d0..a0ff73f 100644 --- a/README.md +++ b/README.md @@ -59,14 +59,14 @@ or directlly download and run the [precompiled binary](https://github.com/ngchai ### transact ```bash -./ngwallet transact 10010 --participants 10011 --values 1.5 # send 1.5 NG to 10011 -./ngwallet transact 10010 --participants 10011,10012 --values 1.5,2.33 # send 1.5 NG to 10011 and 2.33 to 10012 +./ngwallet transact --participants 10011 --values 1.5 # send 1.5 NG to 10011 +./ngwallet transact --participants 10011,10012 --values 1.5,2.33 # send 1.5 NG to 10011 and 2.33 to 10012 ``` ## logout ```bash -./ngwallet logout 10010 # logout account 10010 1.5 NG to 10011 +./ngwallet logout # logout address' account ``` ## check diff --git a/bin/ngwallet.dart b/bin/ngwallet.dart index c84e0a0..04cc869 100644 --- a/bin/ngwallet.dart +++ b/bin/ngwallet.dart @@ -57,6 +57,15 @@ class JsonRpcCMD extends Command { NgRPCClient get client { return NgRPCClient(daemon); } + + Future get convener async { + var addr = getBS58AddressFromPrivateKey(await privateKey); + var acc = client.getAccountByAddr(addr); + if ((await acc) == null) { + throw ('local address $addr doesn\'t have account, please register if you wanna sending coins'); + } + return (await acc)['num']; + } } class CheckTxCMD extends JsonRpcCMD { @@ -165,9 +174,7 @@ class GetAccountCMD extends JsonRpcCMD { Future run() async { switch (argResults.arguments.length) { case 0: - var account = await client - .getAccountByAddr(getBS58AddressFromPrivateKey(await privateKey)); - print(account); + print(await convener); break; case 1: var account = await client.getAccountByAddr(argResults.arguments[0]); @@ -228,19 +235,17 @@ class SendTransactionTxCMD extends JsonRpcCMD { argParser.addMultiOption('values', defaultsTo: []); argParser.addOption('fee', defaultsTo: '0.0'); argParser.addOption('extra', defaultsTo: ''); - argParser.addSeparator('''argument 0: '''); } @override Future run() async { - var convener = int.parse(checkEmpty(argResults.arguments[0], 'convener')); var participants = argResults['participants']; var values = LStr2LNum(argResults['values']); var fee = num.parse(checkEmpty(argResults['fee'], 'fee')); var extra = argResults['extra']; - var unsignedTx = - await client.genTransaction(convener, participants, values, fee, extra); + var unsignedTx = await client.genTransaction( + await convener, participants, values, fee, extra); var signedTx = await client.signTx([await privateKey], unsignedTx); print('signed raw Tx is ' + await signedTx); var hash = await client.sendTx(signedTx); @@ -321,20 +326,15 @@ class SendAssignTxCMD extends JsonRpcCMD { argParser.addOption('extra'); } - @override - final usageFooter = '''argument 0: '''; - @override void run() async { if (argResults.arguments.length != 1) { throw ArgumentError; } - - var convener = int.parse(checkEmpty(argResults.arguments[0], 'convener')); var fee = num.parse(argResults['fee']); var extra = argResults['extra']; - var unsignedTx = await client.genAssign(convener, fee, extra); + var unsignedTx = await client.genAssign(await convener, fee, extra); var signedTx = await client.signTx([await privateKey], unsignedTx); print('signed raw Tx is ' + await signedTx); var hash = await client.sendTx(signedTx); @@ -354,20 +354,16 @@ class SendAppendTxCMD extends JsonRpcCMD { argParser.addOption('extra'); } - @override - final usageFooter = '''argument 0: '''; - @override void run() async { if (argResults.arguments.length != 1) { throw ArgumentError; } - var convener = int.parse(checkEmpty(argResults.arguments[0], 'convener')); var fee = num.parse(checkEmpty(argResults['fee'], 'fee')); var extra = argResults['extra']; - var unsignedTx = await client.genAssign(convener, fee, extra); + var unsignedTx = await client.genAssign(await convener, fee, extra); var signedTx = await client.signTx([await privateKey], unsignedTx); print('signed raw Tx is ' + await signedTx); var hash = await client.sendTx(signedTx); diff --git a/pubspec.yaml b/pubspec.yaml index d760080..12e1225 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: ngwallet description: A sample CLI wallet to NGIN. -version: 0.1.0 +version: 0.1.2 homepage: https://ngin.sh environment: