Skip to content

Commit

Permalink
autofill convener
Browse files Browse the repository at this point in the history
  • Loading branch information
c0mm4nd committed Nov 15, 2020
1 parent c29882b commit 858dea1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.2

- no need to input convener any longer, wallet will auto recognize

## 0.1.1

- Shorten the commands
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 14 additions & 18 deletions bin/ngwallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ class JsonRpcCMD extends Command {
NgRPCClient get client {
return NgRPCClient(daemon);
}

Future<int> 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 {
Expand Down Expand Up @@ -165,9 +174,7 @@ class GetAccountCMD extends JsonRpcCMD {
Future<void> 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]);
Expand Down Expand Up @@ -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: <Convener>''');
}

@override
Future<void> 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);
Expand Down Expand Up @@ -321,20 +326,15 @@ class SendAssignTxCMD extends JsonRpcCMD {
argParser.addOption('extra');
}

@override
final usageFooter = '''argument 0: <Convener>''';

@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);
Expand All @@ -354,20 +354,16 @@ class SendAppendTxCMD extends JsonRpcCMD {
argParser.addOption('extra');
}

@override
final usageFooter = '''argument 0: <Convener>''';

@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);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 858dea1

Please sign in to comment.