Skip to content

Commit 49c3ab0

Browse files
committed
addressed ebuchman comments
1 parent 05c975e commit 49c3ab0

File tree

5 files changed

+31
-34
lines changed

5 files changed

+31
-34
lines changed

cmd/commands/utils.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,40 +39,38 @@ func StripHex(s string) string {
3939
return s
4040
}
4141

42+
//regex codes for extracting coins from CLI input
43+
var reDenom = regexp.MustCompile("([^\\d\\W]+)")
44+
var reAmt = regexp.MustCompile("(\\d+)")
45+
4246
func ParseCoin(str string) (types.Coin, error) {
4347

4448
var coin types.Coin
4549

46-
coins, err := ParseCoins(str)
47-
48-
if err != nil {
49-
return coin, err
50-
}
51-
52-
if len(coins) > 0 {
53-
coin = coins[0]
50+
if len(str) > 0 {
51+
amt, err := strconv.Atoi(reAmt.FindString(str))
52+
if err != nil {
53+
return coin, err
54+
}
55+
denom := reDenom.FindString(str)
56+
coin = types.Coin{denom, int64(amt)}
5457
}
5558

5659
return coin, nil
5760
}
5861

59-
//regex codes from
60-
var reAmt = regexp.MustCompile("(\\d+)")
61-
var reCoin = regexp.MustCompile("([^\\d\\W]+)")
62-
6362
func ParseCoins(str string) (types.Coins, error) {
6463

6564
split := strings.Split(str, ",")
6665
var coins []types.Coin
6766

6867
for _, el := range split {
6968
if len(el) > 0 {
70-
amt, err := strconv.Atoi(reAmt.FindString(el))
69+
coin, err := ParseCoin(el)
7170
if err != nil {
7271
return coins, err
7372
}
74-
coin := reCoin.FindString(el)
75-
coins = append(coins, types.Coin{coin, int64(amt)})
73+
coins = append(coins, coin)
7674
}
7775
}
7876

docs/guide/basecoin-basics.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ The first account is flush with cash, while the second account doesn't exist.
9191
Let's send funds from the first account to the second:
9292

9393
```
94-
basecoin tx send --to 0x1DA7C74F9C219229FD54CC9F7386D5A3839F0090 --amount 10
94+
basecoin tx send --to 0x1DA7C74F9C219229FD54CC9F7386D5A3839F0090 --amount 10blank
9595
```
9696

9797
By default, the CLI looks for a `priv_validator.json` to sign the transaction with,
9898
so this will only work if you are in the `$GOPATH/src/github.com/tendermint/basecoin/data`.
9999
To specify a different key, we can use the `--from` flag.
100100

101-
Now if we check the second account, it should have `10` coins!
101+
Now if we check the second account, it should have `10` 'blank' coins!
102102

103103
```
104104
basecoin account 0x1DA7C74F9C219229FD54CC9F7386D5A3839F0090
@@ -107,15 +107,15 @@ basecoin account 0x1DA7C74F9C219229FD54CC9F7386D5A3839F0090
107107
We can send some of these coins back like so:
108108

109109
```
110-
basecoin tx send --to 0x1B1BE55F969F54064628A63B9559E7C21C925165 --from key2.json --amount 5
110+
basecoin tx send --to 0x1B1BE55F969F54064628A63B9559E7C21C925165 --from key2.json --amount 5blank
111111
```
112112

113113
Note how we use the `--from` flag to select a different account to send from.
114114

115115
If we try to send too much, we'll get an error:
116116

117117
```
118-
basecoin tx send --to 0x1B1BE55F969F54064628A63B9559E7C21C925165 --from key2.json --amount 100
118+
basecoin tx send --to 0x1B1BE55F969F54064628A63B9559E7C21C925165 --from key2.json --amount 100blank
119119
```
120120

121121
See `basecoin tx send --help` for additional details.

docs/guide/example-plugin.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,9 @@ OPTIONS:
132132
--node value Tendermint RPC address (default: "tcp://localhost:46657")
133133
--chain_id value ID of the chain for replay protection (default: "test_chain_id")
134134
--from value Path to a private key to sign the transaction (default: "key.json")
135-
--amount value Amount of coins to send in the transaction (default: 0)
136-
--coin value Specify a coin denomination (default: "mycoin")
135+
--amount value Coins to send in transaction of the format <amt><coin>,<amt2><coin2>,... (eg: 1btc,2gold,5silver)
137136
--gas value The amount of gas for the transaction (default: 0)
138-
--fee value The transaction fee (default: 0)
137+
--fee value Coins for the transaction fee of the format <amt><coin>
139138
--sequence value Sequence number for the account (default: 0)
140139
--valid Set this to make the transaction valid
141140
```
@@ -363,25 +362,25 @@ example-plugin start --in-proc
363362
In another window, we can try sending some transactions:
364363

365364
```
366-
example-plugin tx send --to 0x1B1BE55F969F54064628A63B9559E7C21C925165 --amount 100 --coin gold --chain_id example-chain
365+
example-plugin tx send --to 0x1B1BE55F969F54064628A63B9559E7C21C925165 --amount 100gold --chain_id example-chain
367366
```
368367

369-
Note the `--coin` and `--chain_id` flags. In the [previous tutorial](basecoin-basics.md),
370-
we didn't need them because we were using the default coin type ("mycoin") and chain ID ("test_chain_id").
371-
Now that we're using custom values, we need to specify them explicitly on the command line.
368+
Note the `--chain_id` flag. In the [previous tutorial](basecoin-basics.md),
369+
we didn't include it because we were using the default chain ID ("test_chain_id").
370+
Now that we're using a custom chain, we need to specify the chain explicitly on the command line.
372371

373372
Ok, so that's how we can send a `SendTx` transaction using our `example-plugin` CLI,
374373
but we were already able to do that with the `basecoin` CLI.
375374
With our new CLI, however, we can also send an `ExamplePluginTx`:
376375

377376
```
378-
example-plugin tx example --amount 1 --coin gold --chain_id example-chain
377+
example-plugin tx example --amount 1gold --chain_id example-chain
379378
```
380379

381380
The transaction is invalid! That's because we didn't specify the `--valid` flag:
382381

383382
```
384-
example-plugin tx example --valid --amount 1 --coin gold --chain_id example-chain
383+
example-plugin tx example --valid --amount 1gold --chain_id example-chain
385384
```
386385

387386
Tada! We successfuly created, signed, broadcast, and processed our custom transaction type.
@@ -401,7 +400,7 @@ which contains only an integer.
401400
If we send another transaction, and then query again, we'll see the value increment:
402401

403402
```
404-
example-plugin tx example --valid --amount 1 --coin gold --chain_id example-chain
403+
example-plugin tx example --valid --amount 1gold --chain_id example-chain
405404
example-plugin query ExamplePlugin.State
406405
```
407406

docs/guide/ibc.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ export CHAIN_FLAGS2="--chain_id $CHAIN_ID2 --from ./data/chain2/basecoin/key.jso
236236
Let's start by registering `test_chain_1` on `test_chain_2`:
237237

238238
```
239-
basecoin tx ibc --amount 10 $CHAIN_FLAGS2 register --chain_id $CHAIN_ID1 --genesis ./data/chain1/tendermint/genesis.json
239+
basecoin tx ibc --amount 10blank $CHAIN_FLAGS2 register --chain_id $CHAIN_ID1 --genesis ./data/chain1/tendermint/genesis.json
240240
```
241241

242242
Now we can create the outgoing packet on `test_chain_1`:
243243

244244
```
245-
basecoin tx ibc --amount 10 $CHAIN_FLAGS1 packet create --from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload 0xDEADBEEF --sequence 1
245+
basecoin tx ibc --amount 10blank $CHAIN_FLAGS1 packet create --from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload 0xDEADBEEF --sequence 1
246246
```
247247

248248
Note our payload is just `DEADBEEF`.
@@ -270,7 +270,7 @@ The former is used as input for later commands; the latter is human-readable, so
270270
Let's send this updated information about `test_chain_1` to `test_chain_2`:
271271

272272
```
273-
basecoin tx ibc --amount 10 $CHAIN_FLAGS2 update --header 0x<header>--commit 0x<commit>
273+
basecoin tx ibc --amount 10blank $CHAIN_FLAGS2 update --header 0x<header>--commit 0x<commit>
274274
```
275275

276276
where `<header>` and `<commit>` are the hex-encoded header and commit returned by the previous `block` command.
@@ -280,7 +280,7 @@ along with proof the packet was committed on `test_chain_1`. Since `test_chain_2
280280
of `test_chain_1`, it will be able to verify the proof!
281281

282282
```
283-
basecoin tx ibc --amount 10 $CHAIN_FLAGS2 packet post --from $CHAIN_ID1 --height <height + 1> --packet 0x<packet> --proof 0x<proof>
283+
basecoin tx ibc --amount 10blank $CHAIN_FLAGS2 packet post --from $CHAIN_ID1 --height <height + 1> --packet 0x<packet> --proof 0x<proof>
284284
```
285285

286286
Here, `<height + 1>` is one greater than the height retuned by the previous `query` command, and `<packet>` and `<proof>` are the

docs/guide/src/example-plugin/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (ep *ExamplePlugin) RunTx(store types.KVStore, ctx types.CallContext, txByt
6969
return abci.OK
7070
}
7171

72-
func (cp *ExamplePlugin) InitChain(store types.KVStore, vals []*abci.Validator) {
72+
func (ep *ExamplePlugin) InitChain(store types.KVStore, vals []*abci.Validator) {
7373
}
7474

7575
func (ep *ExamplePlugin) BeginBlock(store types.KVStore, hash []byte, header *abci.Header) {

0 commit comments

Comments
 (0)