diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fb67e697c..d0c77c03bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ BREAKING CHANGES: - complete overhaul on how tx and query subcommands are added. (see counter or trackomatron for examples) - no longer supports counter app (see new countercli) - basecoin + - `basecoin init` takes an argument, an address to allocate funds to in the genesis + - removed key2.json - removed all client side functionality from it (use basecli now for proofs) - no tx subcommand - no query subcommand @@ -27,6 +29,7 @@ BREAKING CHANGES: - removed `example-plugin`, put `counter` inside `docs/guide` ENHANCEMENTS: +- `basecoin init` support `--chain-id` - intergrates tendermint 0.10.0 (not the rc-2, but the real thing) - commands return error code (1) on failure for easier script testing - add `reset_all` to basecli, and never delete keys on `init` diff --git a/cmd/basecli/README.md b/cmd/basecli/README.md index 6e00f3d851..2443c92ae5 100644 --- a/cmd/basecli/README.md +++ b/cmd/basecli/README.md @@ -4,13 +4,6 @@ To keep things clear, let's have two shells... `$` is for basecoin (server), `%` is for basecli (client) -## Set up a clean basecoin, but don't start the chain - -``` -$ export BCHOME=~/.demoserve -$ basecoin init -``` - ## Set up your basecli with a new key ``` @@ -24,16 +17,15 @@ And set up a few more keys for fun... ``` % basecli keys new buddy % basecli keys list -% ME=`basecli keys get demo -o json | jq .address | tr -d '"'` -% YOU=`basecli keys get buddy -o json | jq .address | tr -d '"'` +% ME=$(basecli keys get demo | awk '{print $2}') +% YOU=$(basecli keys get buddy | awk '{print $2}') ``` -## Update genesis so you are rich, and start +## Set up a clean basecoin, initialized with your account ``` -$ vi $BCHOME/genesis.json --> cut/paste your pubkey from the results above - +$ export BCHOME=~/.demoserve +$ basecoin init $ME $ basecoin start ``` @@ -46,8 +38,8 @@ $ basecoin start ## Check your balances... ``` -% basecli proof state get --app=account --key=$ME -% basecli proof state get --app=account --key=$YOU +% basecli query account $ME +% basecli query account $YOU ``` ## Send the money @@ -55,9 +47,7 @@ $ basecoin start ``` % basecli tx send --name demo --amount 1000mycoin --sequence 1 --to $YOU -> copy hash to HASH -% basecli proof tx get --key $HASH - -% basecli proof tx get --key $HASH --app base -% basecli proof state get --key $YOU --app account +% basecli query tx $HASH +% basecli query account $YOU ``` diff --git a/cmd/basecli/commands/apptx.go b/cmd/basecli/commands/apptx.go index 1325427d37..acfc5932d1 100644 --- a/cmd/basecli/commands/apptx.go +++ b/cmd/basecli/commands/apptx.go @@ -51,7 +51,7 @@ func (s *AppTx) Signers() ([]crypto.PubKey, error) { func (s *AppTx) TxBytes() ([]byte, error) { // TODO: verify it is signed - // Code and comment from: basecoin/cmd/commands/tx.go + // Code and comment from: basecoin/cmd/basecoin/commands/tx.go // Don't you hate having to do this? // How many times have I lost an hour over this trick?! txBytes := wire.BinaryBytes(bc.TxS{s.Tx}) diff --git a/cmd/basecli/commands/query.go b/cmd/basecli/commands/query.go index 5b616dc75f..ac17cbdd92 100644 --- a/cmd/basecli/commands/query.go +++ b/cmd/basecli/commands/query.go @@ -1,9 +1,11 @@ package commands import ( + "github.com/pkg/errors" "github.com/spf13/cobra" wire "github.com/tendermint/go-wire" + lc "github.com/tendermint/light-client" proofcmd "github.com/tendermint/light-client/commands/proofs" "github.com/tendermint/light-client/proofs" @@ -25,7 +27,9 @@ func doAccountQuery(cmd *cobra.Command, args []string) error { acc := new(btypes.Account) proof, err := proofcmd.GetAndParseAppProof(key, &acc) - if err != nil { + if lc.IsNoDataErr(err) { + return errors.Errorf("Account bytes are empty for address %X ", addr) + } else if err != nil { return err } diff --git a/cmd/basecli/commands/sendtx.go b/cmd/basecli/commands/sendtx.go index 15c5d58719..1a338ef29e 100644 --- a/cmd/basecli/commands/sendtx.go +++ b/cmd/basecli/commands/sendtx.go @@ -50,7 +50,7 @@ func (s *SendTx) Signers() ([]crypto.PubKey, error) { func (s *SendTx) TxBytes() ([]byte, error) { // TODO: verify it is signed - // Code and comment from: basecoin/cmd/commands/tx.go + // Code and comment from: basecoin/cmd/basecoin/commands/tx.go // Don't you hate having to do this? // How many times have I lost an hour over this trick?! txBytes := wire.BinaryBytes(struct { diff --git a/cmd/commands/ibc.go b/cmd/basecoin/commands/ibc.go similarity index 100% rename from cmd/commands/ibc.go rename to cmd/basecoin/commands/ibc.go diff --git a/cmd/commands/init.go b/cmd/basecoin/commands/init.go similarity index 70% rename from cmd/commands/init.go rename to cmd/basecoin/commands/init.go index 2cfbbcd94a..e9f20247ac 100644 --- a/cmd/commands/init.go +++ b/cmd/basecoin/commands/init.go @@ -1,6 +1,7 @@ package commands import ( + "fmt" "io/ioutil" "os" "path" @@ -17,6 +18,18 @@ var ( } ) +//flags +var ( + chainIDFlag string +) + +func init() { + flags := []Flag2Register{ + {&chainIDFlag, "chain-id", "test_chain_id", "Chain ID"}, + } + RegisterFlags(InitCmd, flags) +} + // returns 1 iff it set a file, otherwise 0 (so we can add them) func setupFile(path, data string, perm os.FileMode) (int, error) { _, err := os.Stat(path) @@ -37,13 +50,17 @@ func initCmd(cmd *cobra.Command, args []string) error { return err } + if len(args) != 1 { + return fmt.Errorf("`init` takes one argument, a basecoin account address. Generate one using `basecli keys new mykey`") + } + userAddr := args[0] + // initalize basecoin genesisFile := cfg.GenesisFile() privValFile := cfg.PrivValidatorFile() - key1File := path.Join(cfg.RootDir, "key.json") - key2File := path.Join(cfg.RootDir, "key2.json") + keyFile := path.Join(cfg.RootDir, "key.json") - mod1, err := setupFile(genesisFile, GenesisJSON, 0644) + mod1, err := setupFile(genesisFile, GetGenesisJSON(chainIDFlag, userAddr), 0644) if err != nil { return err } @@ -51,17 +68,13 @@ func initCmd(cmd *cobra.Command, args []string) error { if err != nil { return err } - mod3, err := setupFile(key1File, Key1JSON, 0400) - if err != nil { - return err - } - mod4, err := setupFile(key2File, Key2JSON, 0400) + mod3, err := setupFile(keyFile, KeyJSON, 0400) if err != nil { return err } - if (mod1 + mod2 + mod3 + mod4) > 0 { - logger.Info("Initialized Basecoin", "genesis", genesisFile, "key", key1File) + if (mod1 + mod2 + mod3) > 0 { + logger.Info("Initialized Basecoin", "genesis", genesisFile, "priv_validator", privValFile) } else { logger.Info("Already initialized", "priv_validator", privValFile) } @@ -86,9 +99,13 @@ var PrivValJSON = `{ } }` -var GenesisJSON = `{ +// GetGenesisJSON returns a new tendermint genesis with Basecoin app_options +// that grant a large amount of "mycoin" to a single address +// TODO: A better UX for generating genesis files +func GetGenesisJSON(chainID, addr string) string { + return fmt.Sprintf(`{ "app_hash": "", - "chain_id": "test_chain_id", + "chain_id": "%s", "genesis_time": "0001-01-01T00:00:00.000Z", "validators": [ { @@ -102,10 +119,7 @@ var GenesisJSON = `{ ], "app_options": { "accounts": [{ - "pub_key": { - "type": "ed25519", - "data": "619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279" - }, + "address": "%s", "coins": [ { "denom": "mycoin", @@ -114,9 +128,11 @@ var GenesisJSON = `{ ] }] } -}` +}`, chainID, addr) +} -var Key1JSON = `{ +// TODO: remove this once not needed for relay +var KeyJSON = `{ "address": "1B1BE55F969F54064628A63B9559E7C21C925165", "priv_key": { "type": "ed25519", @@ -127,15 +143,3 @@ var Key1JSON = `{ "data": "619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279" } }` - -var Key2JSON = `{ - "address": "1DA7C74F9C219229FD54CC9F7386D5A3839F0090", - "priv_key": { - "type": "ed25519", - "data": "34BAE9E65CE8245FAD035A0E3EED9401BDE8785FFB3199ACCF8F5B5DDF7486A8352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8" - }, - "pub_key": { - "type": "ed25519", - "data": "352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8" - } -}` diff --git a/cmd/commands/key.go b/cmd/basecoin/commands/key.go similarity index 100% rename from cmd/commands/key.go rename to cmd/basecoin/commands/key.go diff --git a/cmd/commands/plugin_util.go b/cmd/basecoin/commands/plugin_util.go similarity index 100% rename from cmd/commands/plugin_util.go rename to cmd/basecoin/commands/plugin_util.go diff --git a/cmd/commands/relay.go b/cmd/basecoin/commands/relay.go similarity index 100% rename from cmd/commands/relay.go rename to cmd/basecoin/commands/relay.go diff --git a/cmd/commands/reset.go b/cmd/basecoin/commands/reset.go similarity index 100% rename from cmd/commands/reset.go rename to cmd/basecoin/commands/reset.go diff --git a/cmd/commands/root.go b/cmd/basecoin/commands/root.go similarity index 100% rename from cmd/commands/root.go rename to cmd/basecoin/commands/root.go diff --git a/cmd/commands/start.go b/cmd/basecoin/commands/start.go similarity index 100% rename from cmd/commands/start.go rename to cmd/basecoin/commands/start.go diff --git a/cmd/commands/utils.go b/cmd/basecoin/commands/utils.go similarity index 100% rename from cmd/commands/utils.go rename to cmd/basecoin/commands/utils.go diff --git a/cmd/commands/utils_test.go b/cmd/basecoin/commands/utils_test.go similarity index 100% rename from cmd/commands/utils_test.go rename to cmd/basecoin/commands/utils_test.go diff --git a/cmd/commands/version.go b/cmd/basecoin/commands/version.go similarity index 100% rename from cmd/commands/version.go rename to cmd/basecoin/commands/version.go diff --git a/cmd/basecoin/main.go b/cmd/basecoin/main.go index 5d74ae5585..23c46c7680 100644 --- a/cmd/basecoin/main.go +++ b/cmd/basecoin/main.go @@ -5,7 +5,7 @@ import ( "github.com/spf13/cobra" - "github.com/tendermint/basecoin/cmd/commands" + "github.com/tendermint/basecoin/cmd/basecoin/commands" "github.com/tendermint/tmlibs/cli" ) diff --git a/docs/guide/basecoin-basics.md b/docs/guide/basecoin-basics.md index 9692f31099..716fddb970 100644 --- a/docs/guide/basecoin-basics.md +++ b/docs/guide/basecoin-basics.md @@ -14,56 +14,51 @@ go get -u github.com/tendermint/basecoin/cmd/... If you have trouble, see the [installation guide](install.md). +Note the above command installs two binaries: `basecoin` and `basecli`. +The former is the running node. The latter is a command-line light-client. + +## Generate some keys + +Let's generate two keys, one to receive an initial allocation of coins, +and one to send some coins to later: + +``` +# WARNING: this will wipe out any existing info in the ~/.basecli dir +# including private keys, don't run if you have lots of local state already +basecli reset_all +basecli keys new cool +basecli keys new friend +``` + +You'll need to enter passwords. You can view your key names and addresses with `basecli keys list`, +or see a particular key's address with `basecli keys get `. + ## Initialize Basecoin + To initialize a new Basecoin blockchain, run: ``` # WARNING: this will wipe out any existing info in the ~/.basecoin dir # don't run if you have lots of local state already rm -rf ~/.basecoin -basecoin init +basecoin init
+``` + +If you prefer not to copy-paste, you can provide the address programatically: + +``` +basecoin init $(basecli keys get cool | awk '{print $2}') ``` This will create the necessary files for a Basecoin blockchain with one -validator and one account in `~/.basecoin`. For more options on setup, see the +validator and one account (corresponding to your key) in `~/.basecoin`. For more options on setup, see the [guide to using the Basecoin tool](/docs/guide/basecoin-tool.md). -For this example, we will change the genesis account to a new account named -`cool`. First create a new account: - -``` -# WARNING: this will wipe out any existing info in the ~/.basecli dir -# including private keys, don't run if you have lots of local state already -basecli reset_all -basecli keys new cool -``` - -While we're at it let's setup a second account which we will use later in the tutorial - -``` -basecli keys new friend -``` - -Next we need to copy in the public address from our new key into the genesis block: - -``` -basecli keys get cool -o=json -vi ~/.basecoin/genesis.json --> cut/paste your pubkey from the results above -``` -or alternatively, without manual copy pasting: -``` -GENKEY=`basecli keys get cool -o json | jq .pubkey.data` -GENJSON=`cat ~/.basecoin/genesis.json` -echo $GENJSON | jq '.app_options.accounts[0].pub_key.data='$GENKEY > ~/.basecoin/genesis.json -``` - -Hurray! you are very rich and cool on this blockchain now. +If you like, you can manually add some more accounts to the blockchain by generating keys and editing the `~/.basecoin/genesis.json`. ## Start - Now we can start Basecoin: ``` @@ -74,22 +69,26 @@ You should see blocks start streaming in! ## Initialize Light-Client -Now that Basecoin is running we can initialize the light-client utility named -`basecli`. Basecli is used for sending transactions and querying the state. +Now that Basecoin is running we can initialize `basecli`, the light-client utility. +Basecli is used for sending transactions and querying the state. Leave Basecoin running and open a new terminal window. Here run: ``` basecli init --chain-id=test_chain_id --node=tcp://localhost:46657 ``` +Note it will ask you to verify the validator hash. For a blockchain on your local computer, don't worry about it. +If you're connecting to a blockchain over the internet, you should verify that the validator hash is correct. +This is so that all queries done with `basecli` can be cryptographically proven to be correct according to a known validator set. + ## Send transactions Now we are ready to send some transactions. First Let's check the balance of -the two accounts we setup earlier these two accounts: +the two accounts we setup earlier: ``` -ME=`basecli keys get cool -o=json | jq .address | tr -d '"'` -YOU=`basecli keys get friend -o=json | jq .address | tr -d '"'` +ME=$(basecli keys get cool | awk '{print $2}') +YOU=$(basecli keys get friend | awk '{print $2}') basecli query account $ME basecli query account $YOU ``` @@ -101,9 +100,6 @@ Let's send funds from the first account to the second: basecli tx send --name=cool --amount=1000mycoin --to=0x$YOU --sequence=1 ``` -By default, the CLI looks for a `key.json` to sign the transaction with. -To specify a different key, we can use the `--from` flag. - Now if we check the second account, it should have `1000` 'mycoin' coins! ``` @@ -124,21 +120,42 @@ If we try to send too much, we'll get an error: basecli tx send --name=friend --amount=500000mycoin --to=$ME --sequence=1 ``` -And if you want to see the original tx, as well as verifying that it -really is in the blockchain, look at the send response: +Let's send another transaction: ``` basecli tx send --name=cool --amount=2345mycoin --to=$YOU --sequence=2 -# TXHASH from the json output -basecli query tx $TXHASH +``` + +Note the `hash` value in the response - this is the hash of the transaction. +We can query for the transaction by this hash: + +``` +basecli query tx ``` See `basecli tx send --help` for additional details. -For a better understanding of the options, it helps to understand the +## Proof + +Even if you don't see it in the UI, the result of every query comes with a proof. +This is a Merkle proof that the result of the query is actually contained in the state. +and the state's Merkle root is contained in a recent block header. +Behind the scenes, `countercli` will not only verify that this state matches the header, +but also that the header is properly signed by the known validator set. +It will even update the validator set as needed, so long +as there have not been major changes and it is secure to do so. So, if you wonder +why the query may take a second... there is a lot of work going on in the +background to make sure even a lying full node can't trick your client. + +In a latter [guide on InterBlockchainCommunication](ibc.md), we'll use these +proofs to post transactions to other chains. + +## Accounts and Transactions + +For a better understanding of how to further use the tools, it helps to understand the underlying data structures. -## Accounts +### Accounts The Basecoin state consists entirely of a set of accounts. Each account contains a public key, a balance in many different coin denominations, and a @@ -162,6 +179,9 @@ type Coin struct { } ``` +If you want to add more coins to a blockchain, you can do so manually in the `~/.basecoin/genesis.json` before +you start the blockchain for the first time. + Accounts are serialized and stored in a Merkle tree under the key `base/a/
`, where `
` is the address of the account. Typically, the address of the account is the 20-byte `RIPEMD160` hash of the @@ -170,7 +190,7 @@ public key, but other formats are acceptable as well, as defined in the Merkle tree used in Basecoin is a balanced, binary search tree, which we call an [IAVL tree](https://github.com/tendermint/go-merkle). -## Transactions +### Transactions Basecoin defines a simple transaction type, the `SendTx`, which allows tokens to be sent to other accounts. The `SendTx` takes a list of inputs and a list @@ -229,9 +249,9 @@ transaction. ## Conclusion -In this guide, we introduced the `basecoin` tool, demonstrated how to use it to -send tokens between accounts, and discussed the underlying data types for -accounts and transactions, specifically the `Account` and the `SendTx`. In the -[next guide](basecoin-plugins.md), we introduce the Basecoin plugin system, +In this guide, we introduced the `basecoin` and `basecli` tools, +demonstrated how to start a new basecoin blockchain and how to send tokens between accounts, +and discussed the underlying data types for accounts and transactions, specifically the `Account` and the `SendTx`. +In the [next guide](basecoin-plugins.md), we introduce the Basecoin plugin system, which uses a new transaction type, the `AppTx`, to extend the functionality of the Basecoin system with arbitrary logic. diff --git a/docs/guide/basecoin-plugins.md b/docs/guide/basecoin-plugins.md index 5c2114d0cc..8bdee823ed 100644 --- a/docs/guide/basecoin-plugins.md +++ b/docs/guide/basecoin-plugins.md @@ -1,27 +1,32 @@ # Basecoin Plugins In the [previous guide](basecoin-basics.md), we saw how to use the `basecoin` -tool to start a blockchain and send transactions. We also learned about +tool to start a blockchain and the `basecli` tools to send transactions. We also learned about `Account` and `SendTx`, the basic data types giving us a multi-asset -cryptocurrency. Here, we will demonstrate how to extend the `basecoin` tool to -use another transaction type, the `AppTx`, to send data to a custom plugin. In -this example we explore a simple plugin name `counter`. +cryptocurrency. Here, we will demonstrate how to extend the tools to +use another transaction type, the `AppTx`, so we can send data to a custom plugin. In +this example we explore a simple plugin named `counter`. ## Example Plugin -The design of the `basecoin` tool makes it easy to extend for custom -functionality. The Counter plugin is bundled with basecoin, so if you have -already [installed basecoin](install.md) then you should be able to run a full -node with `counter` and the a light-client `countercli` from terminal. The -Counter plugin is just like the `basecoin` tool. They both use the same -library of commands, including one for signing and broadcasting `SendTx`. +The design of the `basecoin` and `basecli` tools makes it easy to extend for custom +functionality. We provide examples of such extensions in the basecoin repository under `docs/guide/counter`. +You can install them from the basecoin directory with: + +``` +`go install ./docs/guide/counter/cmd/... +``` + +This will give you both the `counter` and `countercli` binaries. +The former is just like `basecoin`, but with the counter plugin activated. +The latter is just like `basecli`, but with support for sending transactions to the counter plugin. Counter transactions take two custom inputs, a boolean argument named `valid`, and a coin amount named `countfee`. The transaction is only accepted if both `valid` is set to true and the transaction input coins is greater than `countfee` that the user provides. -A new blockchain can be initialized and started just like with in the [previous +A new blockchain can be initialized and started just like in the [previous guide](basecoin-basics.md): ``` @@ -29,16 +34,12 @@ guide](basecoin-basics.md): rm -rf ~/.counter countercli reset_all -counter init countercli keys new cool countercli keys new friend -GENKEY=`countercli keys get cool -o json | jq .pubkey.data` -GENJSON=`cat ~/.counter/genesis.json` -echo $GENJSON | jq '.app_options.accounts[0].pub_key.data='$GENKEY > ~/.counter/genesis.json +counter init $(countercli keys get cool | awk '{print $2}') counter start - ``` The default files are stored in `~/.counter`. In another window we can @@ -47,7 +48,7 @@ initialize the light-client and send a transaction: ``` countercli init --chain-id=test_chain_id --node=tcp://localhost:46657 -YOU=`countercli keys get friend -o=json | jq .address | tr -d '"'` +YOU=$(countercli keys get friend | awk '{print $2}') countercli tx send --name=cool --amount=1000mycoin --to=0x$YOU --sequence=1 ``` @@ -78,21 +79,12 @@ countercli tx counter --name cool --amount=2mycoin --sequence=4 --valid --countf countercli query counter ``` -The value Counter value should be 2, because we sent a second valid transaction. +The Counter value should be 2, because we sent a second valid transaction. And this time, since we sent a countfee (which must be less than or equal to the total amount sent with the tx), it stores the `TotalFees` on the counter as well. -Even if you don't see it in the UI, the result of the query comes with a proof. -This is a Merkle proof that the state is what we say it is, and ties that query -to a particular header. Behind the scenes, `countercli` will not only verify that -this state matches the header, but also that the header is properly signed by -the known validator set. It will even update the validator set as needed, so long -as there have not been major changes and it is secure to do so. So, if you wonder -why the query may take a second... there is a lot of work going on in the -background to make sure even a lying full node can't trick your client. - -In a latter [guide on InterBlockchainCommunication](ibc.md), we'll use these -proofs to post transactions to other chains. +Keep it mind that, just like with `basecli`, the `countercli` verifies a proof +that the query response is correct and up-to-date. Now, before we implement our own plugin and tooling, it helps to understand the `AppTx` and the design of the plugin system. @@ -178,12 +170,11 @@ alone, but you should change any occurrences of `counter` to whatever your plugin tool is going to be called. You must also register your plugin(s) with the basecoin app with `RegisterStartPlugin`. -The light-client which is located in `cmd/countercli/main.go` allows for is -where transaction and query commands are designated. Similarity this command -can be mostly left alone besides replacing the application name and adding -references to new plugin commands +The light-client is located in `cmd/countercli/main.go` and allows for +transaction and query commands. This file can also be left mostly alone besides replacing the application name and adding +references to new plugin commands. -Next is the custom commands in `cmd/countercli/commands/`. These files is +Next is the custom commands in `cmd/countercli/commands/`. These files are where we extend the tool with any new commands and flags we need to send transactions or queries to our plugin. You define custom `tx` and `query` subcommands, which are registered in `main.go` (avoiding `init()` diff --git a/docs/guide/basecoin-tool.md b/docs/guide/basecoin-tool.md index 0f89f7bd73..eb35ec9ea1 100644 --- a/docs/guide/basecoin-tool.md +++ b/docs/guide/basecoin-tool.md @@ -5,6 +5,15 @@ CLI](/docs/guide/basecoin-basics.md) and [how to implement a plugin](/docs/guide/basecoin-plugins.md). In this tutorial, we provide more details on using the Basecoin tool. +# Generate a Key + +Generate a key using the `basecli` tool: + +``` +basecli keys new mykey +ME=$(basecli keys get mykey | awk '{print $2}') +``` + # Data Directory By default, `basecoin` works out of `~/.basecoin`. To change this, set the @@ -12,14 +21,14 @@ By default, `basecoin` works out of `~/.basecoin`. To change this, set the ``` export BCHOME=~/.my_basecoin_data -basecoin init +basecoin init $ME basecoin start ``` or ``` -BCHOME=~/.my_basecoin_data basecoin init +BCHOME=~/.my_basecoin_data basecoin init $ME BCHOME=~/.my_basecoin_data basecoin start ``` @@ -30,7 +39,7 @@ we use ABCI, we can actually run them in different processes. First, initialize them: ``` -basecoin init +basecoin init $ME ``` This will create a single `genesis.json` file in `~/.basecoin` with the @@ -168,7 +177,7 @@ You can reset all blockchain data by running: basecoin unsafe_reset_all ``` -Similarity you can reset client data by running: +Similarly, you can reset client data by running: ``` basecli reset_all diff --git a/docs/guide/counter/cmd/counter/main.go b/docs/guide/counter/cmd/counter/main.go index 0da66c12f6..c877a51eda 100644 --- a/docs/guide/counter/cmd/counter/main.go +++ b/docs/guide/counter/cmd/counter/main.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tmlibs/cli" - "github.com/tendermint/basecoin/cmd/commands" + "github.com/tendermint/basecoin/cmd/basecoin/commands" "github.com/tendermint/basecoin/docs/guide/counter/plugins/counter" "github.com/tendermint/basecoin/types" ) diff --git a/docs/guide/ibc.md b/docs/guide/ibc.md index aaf4e01b7f..5f82c1f5fc 100644 --- a/docs/guide/ibc.md +++ b/docs/guide/ibc.md @@ -2,11 +2,8 @@ One of the most exciting elements of the Cosmos Network is the InterBlockchain Communication (IBC) protocol, which enables interoperability across different -blockchains. The simplest example of using the IBC protocol is to send a data -packet from one blockchain to another. - -We implemented IBC as a basecoin plugin. and here we'll show you how to use -the Basecoin IBC-plugin to send a packet of data across blockchains! +blockchains. We implemented IBC as a basecoin plugin, and we'll show you +how to use it to send tokens across blockchains! Please note, this tutorial assumes you are familiar with [Basecoin plugins](/docs/guide/basecoin-plugins.md), but we'll explain how IBC works. You @@ -179,9 +176,8 @@ The results of a query can thus be used as proof in an `IBCPacketPostTx`. ## Relay While we need all these packet types internally to keep track of all the -proofs on both chains in a secure manner, for the normal work-flow, where -we just use the FIFO queue on each side for pending message to send as soon -as possible. +proofs on both chains in a secure manner, for the normal work-flow, +we can run a relay node that handles the cross-chain interaction. In this case, there are only two steps. First `basecoin relay init`, which must be run once to register each chain with the other one, @@ -197,11 +193,9 @@ chains to pay for all the ibc packets it will be forwarding. Now that we have all the background knowledge, let's actually walk through the tutorial. -Make sure you have installed -[Tendermint](https://tendermint.com/intro/getting-started/download) and -[basecoin](/docs/guide/install.md). +Make sure you have installed [basecoin and basecli](/docs/guide/install.md). -`basecoin` is a framework for creating new cryptocurrency applications. It +Basecoin is a framework for creating new cryptocurrency applications. It comes with an `IBC` plugin enabled by default. You will also want to install the [jq](https://stedolan.github.io/jq/) for @@ -240,11 +234,7 @@ Prepare the genesis block and start the server: export BCHOME=~/.ibcdemo/chain1/server CHAIN_ID=test-chain-1 PREFIX=1234 -basecoin init - -GENKEY=`basecli keys get money -o json --home=$HOME/.ibcdemo/chain1/client | jq .pubkey.data` -GENJSON=`cat $BCHOME/genesis.json` -echo $GENJSON | jq '.app_options.accounts[0].pub_key.data='$GENKEY | jq ".chain_id=\"$CHAIN_ID\"" > $BCHOME/genesis.json +basecoin init $(basecli keys get money | awk '{print $2}') sed -ie "s/4665/$PREFIX/" $BCHOME/config.toml @@ -257,8 +247,8 @@ have money, the second none: **Client1** ```bash basecli init --chain-id=${CHAIN_ID} --node=tcp://localhost:${PORT} -ME=`basecli keys get money -o=json | jq .address | tr -d '"'` -YOU=`basecli keys get gotnone -o=json | jq .address | tr -d '"'` +ME=$(basecli keys get money | awk '{print $2}') +YOU=$(basecli keys get gotnone | awk '{print $2}') basecli query account $ME basecli query account $YOU ``` @@ -287,12 +277,7 @@ Prepare the genesis block and start the server: export BCHOME=~/.ibcdemo/chain2/server CHAIN_ID=test-chain-2 PREFIX=2345 -basecoin init - - -GENKEY=`basecli keys get moremoney -o json --home=$HOME/.ibcdemo/chain2/client | jq .pubkey.data` -GENJSON=`cat $BCHOME/genesis.json` -echo $GENJSON | jq '.app_options.accounts[0].pub_key.data='$GENKEY | jq ".chain_id=\"$CHAIN_ID\"" > $BCHOME/genesis.json +basecoin init $(basecli keys get moremoney | awk '{print $2}') sed -ie "s/4665/$PREFIX/" $BCHOME/config.toml @@ -305,8 +290,8 @@ have money, the second none: **Client2** ```bash basecli init --chain-id=${CHAIN_ID} --node=tcp://localhost:${PORT} -ME=`basecli keys get moremoney -o=json | jq .address | tr -d '"'` -YOU=`basecli keys get broke -o=json | jq .address | tr -d '"'` +ME=$(basecli keys get moremoney | awk '{print $2}') +YOU=$(basecli keys get broke | awk '{print $2}') basecli query account $ME basecli query account $YOU ``` diff --git a/glide.lock b/glide.lock index 38df58154d..8b96e92922 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ hash: 6eb1119dccf2ab4d0adb870a14cb4408047119be53c8ec4afeaa281bd1d2b457 -updated: 2017-06-15T17:51:21.867322849+02:00 +updated: 2017-06-20T20:55:16.122030554-04:00 imports: - name: github.com/bgentry/speakeasy version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd @@ -127,7 +127,7 @@ imports: - data - data/base58 - name: github.com/tendermint/light-client - version: 4ad913f2728307ec13a3b602b040c29b6a2117b8 + version: 5ba3d0bce406b4b4ce694ca4387b9d086ac0c10f subpackages: - certifiers - certifiers/client @@ -171,7 +171,7 @@ imports: - types - version - name: github.com/tendermint/tmlibs - version: 59a77e7bef092eef0e1f9b44c983dc9e35eed0d6 + version: bd9d0d1637dadf1330e167189d5e5031aadcda6f subpackages: - autofile - cli diff --git a/tests/cli/common.sh b/tests/cli/common.sh index 017da897a4..95269f8422 100644 --- a/tests/cli/common.sh +++ b/tests/cli/common.sh @@ -24,13 +24,9 @@ initServer() { assertNotNull "no chain" $2 CHAIN=$2 SERVER_LOG=$1/${SERVER_EXE}.log - ${SERVER_EXE} init --home=$SERVE_DIR >>$SERVER_LOG - #change the genesis to the first account - GENKEY=$(${CLIENT_EXE} keys get ${RICH} -o json | jq .pubkey.data) - GENJSON=$(cat $SERVE_DIR/genesis.json) - echo $GENJSON | jq '.app_options.accounts[0].pub_key.data='$GENKEY \ - | jq ".chain_id=\"$2\"" > $SERVE_DIR/genesis.json + GENKEY=$(${CLIENT_EXE} keys get ${RICH} | awk '{print $2}') + ${SERVER_EXE} init --chain-id $CHAIN $GENKEY --home=$SERVE_DIR >>$SERVER_LOG # optionally set the port if [ -n "$3" ]; then