Skip to content

Commit

Permalink
Merge PR #1534: Check new rat decimal string length
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiaff authored and cwgoes committed Jul 4, 2018
1 parent cae6b40 commit f119401
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/clients/ledger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Ledger // Cosmos

### Ledger Support for account keys

`gaiacli` now supports derivation of account keys from a Ledger seed. To use this functionality you will need the following:

- A running `gaiad` instance connected to the network you wish to use.
- A `gaiacli` instance configured to connect to your chosen `gaiad` instance.
- A LedgerNano with the `ledger-cosmos` app installed
* Install the Cosmos app onto your Ledger by following the instructions in the [`ledger-cosmos`](https://github.com/cosmos/ledger-cosmos/blob/master/docs/BUILD.md) repository.
* A production-ready version of this app will soon be included in the [Ledger Apps Store](https://www.ledgerwallet.com/apps)

> **NOTE:** Cosmos keys are derived acording to the [BIP 44 Hierarchical Deterministic wallet spec](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki). For more information on Cosmos derivation paths [see the hd package](https://github.com/cosmos/cosmos-sdk/blob/develop/crypto/keys/hd/hdpath.go#L30).
Once you have the Cosmos app installed on your Ledger, and the Ledger is accessible from the machine you are using `gaiacli` from you can create a new account key using the Ledger:

```bash
$ gaiacli keys add {{ .Key.Name }} --ledger
NAME: TYPE: ADDRESS: PUBKEY:
{{ .Key.Name }} ledger cosmosaccaddr1aw64xxr80lwqqdk8u2xhlrkxqaxamkr3e2g943 cosmosaccpub1addwnpepqvhs678gh9aqrjc2tg2vezw86csnvgzqq530ujkunt5tkuc7lhjkz5mj629
```

This key will only be accessible while the Ledger is plugged in and unlocked. To send some coins with this key, run the following:

```bash
$ gaiacli send --name {{ .Key.Name }} --to {{ .Destination.AccAddr }} --chain-id=gaia-7000
```

You will be asked to review and confirm the transaction on the Ledger. Once you do this you should see the result in the console! Now you can use your Ledger to manage your Atoms and Stake!
4 changes: 4 additions & 0 deletions types/rational.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func NewRat(Numerator int64, Denominator ...int64) Rat {
// precision is the number of values after the decimal point which should be read
func NewRatFromDecimal(decimalStr string, prec int) (f Rat, err Error) {
// first extract any negative symbol
if len(decimalStr) == 0 {
return f, ErrUnknownRequest("decimal string is empty")
}

neg := false
if string(decimalStr[0]) == "-" {
neg = true
Expand Down
1 change: 1 addition & 0 deletions types/rational_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestNewFromDecimal(t *testing.T) {
expErr bool
exp Rat
}{
{"", true, Rat{}},
{"0", false, NewRat(0)},
{"1", false, NewRat(1)},
{"1.1", false, NewRat(11, 10)},
Expand Down

0 comments on commit f119401

Please sign in to comment.