Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify #51

Merged
merged 18 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
# Changelog

## 0.3.0 (March 23, 2017)

BREAKING CHANGES:

- Remove `--data` flag and use `BCHOME` to set the home directory (defaults to `~/.basecoin`)
- Remove `--in-proc` flag and start Tendermint in-process by default (expect Tendermint files in $BCHOME/tendermint).
To start just the ABCI app/server, use `basecoin start --without-tendermint`.
- Consolidate genesis files so the Basecoin genesis is an object under `app_options` in Tendermint genesis. For instance:

```
{
"app_hash": "",
"chain_id": "foo_bar_chain",
"genesis_time": "0001-01-01T00:00:00.000Z",
"validators": [
{
"amount": 10,
"name": "",
"pub_key": [
1,
"7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30"
]
}
],
"app_options": {
"accounts": [{
"pub_key": {
"type": "ed25519",
"data": "6880db93598e283a67c4d88fc67a8858aa2de70f713fe94a5109e29c137100c2"
},
"coins": [
{
"denom": "blank",
"amount": 12345
},
{
"denom": "ETH",
"amount": 654321
}
]
}],
"plugin_options": ["plugin1/key1", "value1", "plugin1/key2", "value2"]
}
}
```

Note the array of key-value pairs is now under `app_options.plugin_options` while the `app_options` themselves are well formed.
We also changed `chainID` to `chain_id` and consolidated to have just one of them.

FEATURES:

- Introduce `basecoin init` and `basecoin unsafe_reset_all`

## 0.2.0 (March 6, 2017)

BREAKING CHANGES:
Expand Down
32 changes: 6 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,26 @@ WARNING: Currently uses plain-text private keys for transactions and is otherwis

## Prerequisites

* Go to https://golang.org/doc/install to install Golang.
* You will also need to set the $GOPATH environment variable as per the instructions [here](https://golang.org/doc/code.html#GOPATH).
[Install and setup Golang](https://tendermint.com/docs/guides/install-go).

## Installation

On a good day, basecoin can be installed like a normal Go program:

```
go get -u github.com/tendermint/basecoin/cmd/basecoin
```

See the [install guide](/docs/guide/install.md) for more details.

If that fails, or if another branch is required, you may have to compile from source.
You will first need to install the Golang package manager [`glide`](https://github.com/Masterminds/glide).

```
cd $GOPATH/src/github.com/tendermint/basecoin
git checkout develop # (until we release tendermint v0.9)
make get_vendor_deps
make install
```

This will create the `basecoin` binary in `$GOPATH/bin`.


## Command Line Interface

The basecoin CLI can be used to start a stand-alone basecoin instance (`basecoin start`),
or to start basecoin with Tendermint in the same process (`basecoin start --in-proc`).
It can also be used to send transactions, eg. `basecoin tx send --to 0x4793A333846E5104C46DD9AB9A00E31821B2F301 --amount 100btc,10gold`
See `basecoin --help` and `basecoin [cmd] --help` for more details`.

## Learn more
## Guide

1. Getting started with the [Basecoin tool](/docs/guide/basecoin-basics.md)
1. Getting started with the [Basecoin basics](/docs/guide/basecoin-basics.md)
1. Learn more about [Basecoin's design](/docs/guide/basecoin-design.md)
1. Extend Basecoin [using the plugin system](/docs/guide/example-plugin.md)
1. Learn more about [plugin design](/docs/guide/plugin-design.md)
1. See some [more example applications](/docs/guide/more-examples.md)
1. More features of the [Basecoin tool](/docs/guide/basecoin-tool.md)
1. Learn how to use [InterBlockchain Communication (IBC)](/docs/guide/ibc.md)
1. [Deploy testnets](deployment.md) running your basecoin application.
1. [Deploy testnets](/docs/guide/deployment.md) running your basecoin application.


7 changes: 4 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func (app *Basecoin) SetOption(key string, value string) string {
if plugin == nil {
return "Invalid plugin name: " + pluginName
}
log.Info("SetOption on plugin", "plugin", pluginName, "key", key, "value", value)
log.Notice("SetOption on plugin", "plugin", pluginName, "key", key, "value", value)
return plugin.SetOption(app.state, key, value)
} else {
// Set option on basecoin
switch key {
case "chainID":
case "chain_id":
app.state.SetChainID(value)
return "Success"
case "account":
Expand All @@ -75,7 +75,8 @@ func (app *Basecoin) SetOption(key string, value string) string {
return "Error decoding acc message: " + err.Error()
}
app.state.SetAccount(acc.PubKey.Address(), &acc)
log.Info("SetAccount", "addr", acc.PubKey.Address(), "acc", acc)
log.Notice("SetAccount", "addr", acc.PubKey.Address(), "acc", acc)

return "Success"
}
return "Unrecognized option key " + key
Expand Down
62 changes: 55 additions & 7 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,35 @@ import (
"encoding/json"

"github.com/pkg/errors"
"github.com/tendermint/basecoin/types"
cmn "github.com/tendermint/go-common"
//tmtypes "github.com/tendermint/tendermint/types"
)

func (app *Basecoin) LoadGenesis(path string) error {
kvz, err := loadGenesis(path)
genDoc, err := loadGenesis(path)
if err != nil {
return err
}
for _, kv := range kvz {
app.SetOption(kv.Key, kv.Value)

// set chain_id
app.SetOption("base/chain_id", genDoc.ChainID)

// set accounts
for _, acc := range genDoc.AppOptions.Accounts {
accBytes, err := json.Marshal(acc)
if err != nil {
return err
}
r := app.SetOption("base/account", string(accBytes))
// TODO: SetOption returns an error
log.Notice("Done setting Account via SetOption", "result", r)
}

// set plugin options
for _, kv := range genDoc.AppOptions.pluginOptions {
r := app.SetOption(kv.Key, kv.Value)
log.Notice("Done setting Plugin key-value pair via SetOption", "result", r, "k", kv.Key, "v", kv.Value)
}
return nil
}
Expand All @@ -23,16 +42,45 @@ type keyValue struct {
Value string `json:"value"`
}

func loadGenesis(filePath string) (kvz []keyValue, err error) {
kvz_ := []json.RawMessage{}
// includes tendermint (in the json, we ignore here)
type FullGenesisDoc struct {
ChainID string `json:"chain_id"`
AppOptions *GenesisDoc `json:"app_options"`
}

type GenesisDoc struct {
Accounts []types.Account `json:"accounts"`
PluginOptions []json.RawMessage `json:"plugin_options"`

pluginOptions []keyValue // unmarshaled rawmessages
}

func loadGenesis(filePath string) (*FullGenesisDoc, error) {
bytes, err := cmn.ReadFile(filePath)
if err != nil {
return nil, errors.Wrap(err, "loading genesis file")
}
err = json.Unmarshal(bytes, &kvz_)

// the tendermint genesis is go-wire
// tmGenesis := new(tmtypes.GenesisDoc)
// err = wire.ReadJSONBytes(bytes, tmGenesis)

// the basecoin genesis go-data :)
genDoc := new(FullGenesisDoc)
err = json.Unmarshal(bytes, genDoc)
if err != nil {
return nil, errors.Wrap(err, "parsing genesis file")
return nil, errors.Wrap(err, "unmarshaling genesis file")
}

pluginOpts, err := parseGenesisList(genDoc.AppOptions.PluginOptions)
if err != nil {
return nil, err
}
genDoc.AppOptions.pluginOptions = pluginOpts
return genDoc, nil
}

func parseGenesisList(kvz_ []json.RawMessage) (kvz []keyValue, err error) {
if len(kvz_)%2 != 0 {
return nil, errors.New("genesis cannot have an odd number of items. Format = [key1, value1, key2, value2, ...]")
}
Expand Down
37 changes: 20 additions & 17 deletions app/testdata/genesis.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
[
"base/chainID", "foo_bar_chain",
"base/account", {
"pub_key": {
"type": "ed25519",
"data": "6880db93598e283a67c4d88fc67a8858aa2de70f713fe94a5109e29c137100c2"
},
"coins": [
{
"denom": "blank",
"amount": 12345
{
"chain_id": "foo_bar_chain",
"app_options": {
"accounts": [{
"pub_key": {
"type": "ed25519",
"data": "6880db93598e283a67c4d88fc67a8858aa2de70f713fe94a5109e29c137100c2"
},
{
"denom": "ETH",
"amount": 654321
}
]
"coins": [
{
"denom": "blank",
"amount": 12345
},
{
"denom": "ETH",
"amount": 654321
}
]
}],
"plugin_options": ["plugin1/key1", "value1", "plugin1/key2", "value2"]
}
]
}
2 changes: 2 additions & 0 deletions cmd/basecoin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ func main() {
app.Usage = "basecoin [command] [args...]"
app.Version = version.Version
app.Commands = []cli.Command{
commands.InitCmd,
commands.StartCmd,
commands.TxCmd,
commands.QueryCmd,
commands.KeyCmd,
commands.VerifyCmd,
commands.BlockCmd,
commands.AccountCmd,
commands.UnsafeResetAllCmd,
}
app.Run(os.Args)
}
12 changes: 3 additions & 9 deletions cmd/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ var (
// TODO: move to config file
// eyesCacheSizePtr := flag.Int("eyes-cache-size", 10000, "MerkleEyes db cache size, for embedded")

DirFlag = cli.StringFlag{
Name: "dir",
Value: ".",
Usage: "Root directory",
}

InProcTMFlag = cli.BoolFlag{
Name: "in-proc",
Usage: "Run Tendermint in-process with the App",
WithoutTendermintFlag = cli.BoolFlag{
Name: "without-tendermint",
Usage: "Run the Basecoin app without Tendermint",
}
)

Expand Down
Loading