Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
okwme committed Jun 6, 2019
2 parents ff1c725 + 7be1427 commit 375c7cd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
1 change: 0 additions & 1 deletion tutorial/README.md
Expand Up @@ -43,7 +43,6 @@ Through the course of this tutorial you will create the following files that mak
├── module.go
├── geneis.go
└── types.go

```

Start by creating a new git repository:
Expand Down
1 change: 0 additions & 1 deletion tutorial/app-complete.md
Expand Up @@ -307,7 +307,6 @@ The `initChainer` defines how accounts in `genesis.json` are mapped into the app
The constructor registers the `initChainer` function, but it isn't defined yet. Go ahead and create it:

```go

func (app *nameServiceApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {

var genesisState GenesisState
Expand Down
1 change: 0 additions & 1 deletion tutorial/cn/12-app-complete.md
Expand Up @@ -31,7 +31,6 @@ import (
接下来,你需要在`nameServiceApp`结构体中添加存储的key和`Keepers`,并更新构造函数:

```go

const (
appName = "nameservice"
)
Expand Down
2 changes: 0 additions & 2 deletions tutorial/entrypoint.md
Expand Up @@ -99,7 +99,6 @@ func exportAppStateAndTMValidators(

return nsApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
}

```

Notes on the above code:
Expand Down Expand Up @@ -276,7 +275,6 @@ func initConfig(cmd *cobra.Command) error {
}
return viper.BindPFlag(cli.OutputFlag, cmd.PersistentFlags().Lookup(cli.OutputFlag))
}

```

Note:
Expand Down
3 changes: 0 additions & 3 deletions tutorial/module.md
Expand Up @@ -7,7 +7,6 @@ Start by opening two new files, `module.go` and `genesis.go`. We will implement
Lets start with adding the following code to `module.go`. We will leave a number of the functions unimplemented for now.

```go

package nameservice

import (
Expand Down Expand Up @@ -82,7 +81,6 @@ func (am AppModule) Route() string {
func (am AppModule) NewHandler() types.Handler {
return NewHandler(am.keeper)
}

func (am AppModule) QuerierRoute() string {
return ModuleName
}
Expand All @@ -109,7 +107,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
gs := ExportGenesis(ctx, am.keeper)
return ModuleCdc.MustMarshalJSON(gs)
}

```

To see more examples of AppModule implementation, check out some of the other modules in the SDK such as [x/staking](https://github.com/cosmos/cosmos-sdk/blob/master/x/staking/genesis.go)
Expand Down
36 changes: 23 additions & 13 deletions tutorial/run-rest.md
Expand Up @@ -24,18 +24,29 @@ $ curl -s http://localhost:1317/auth/accounts/$(nscli keys show jack -a)

# Get the sequence and account numbers for alice to construct the below requests
$ curl -s http://localhost:1317/auth/accounts/$(nscli keys show alice -a)
# > {"type":"auth/Account","value":{"address":"cosmos1h7ztnf2zkf4558hdxv5kpemdrg3tf94hnpvgsl","coins":[{"denom":"aliceCoin","amount":"1000"},{"denom":"nametoken","amount":"980"}],"public_key":{"type":"tendermint/PubKeySecp256k1","value":"Avc7qwecLHz5qb1EKDuSTLJfVOjBQezk0KSPDNybLONJ"},"account_number":"1","sequence":"1"}}
# > {"type":"auth/Account","value":{"address":"cosmos1h7ztnf2zkf4558hdxv5kpemdrg3tf94hnpvgsl","coins":[{"denom":"aliceCoin","amount":"1000"},{"denom":"nametoken","amount":"980"}],"public_key":{"type":"tendermint/PubKeySecp256k1","value":"Avc7qwecLHz5qb1EKDuSTLJfVOjBQezk0KSPDNybLONJ"},"account_number":"1","sequence":"2"}}

# Buy another name for jack
# Buy another name for jack, first create the raw transaction
# NOTE: Be sure to specialize this request for your specific environment, also the "buyer" and "from" should be the same address
$ curl -XPOST -s http://localhost:1317/nameservice/names --data-binary '{"base_req":{"from":"jack","password":"foobarbaz","chain_id":"namechain","sequence":"2","account_number":"0"},"name":"jack1.id","amount":"5nametoken","buyer":"cosmos127qa40nmq56hu27ae263zvfk3ey0tkapwk0gq6"}'
# > {"check_tx":{"gasWanted":"200000","gasUsed":"1242"},"deliver_tx":{"log":"Msg 0: ","gasWanted":"200000","gasUsed":"2986","tags":[{"key":"YWN0aW9u","value":"YnV5X25hbWU="}]},"hash":"098996CD7ED4323561AC9011DEA24C70C8FAED2A4A10BC8DE2CE35C1977C3B7A","height":"23"}
curl -XPOST -s http://localhost:1317/nameservice/names --data-binary '{"base_req":{"from":"'$(nscli keys show jack -a)'","chain_id":"namechain"},"name":"jack1.id","amount":"5nametoken","buyer":"'$(nscli keys show jack -a)'"}' > unsignedTx.json

# Then sign this transaction
# NOTE: In a real environment the raw transaction should be signed on the client side. Also the sequence needs to be adjusted, depending on what the query of alice's account has shown.
nscli tx sign unsignedTx.json --from jack --offline --chain-id namechain --sequence 1 --account-number 0 > signedTx.json

# And finally broadcast the signed transaction
nscli tx broadcast signedTx.json
# > { "height": "266", "txhash": "C041AF0CE32FBAE5A4DD6545E4B1F2CB786879F75E2D62C79D690DAE163470BC", "logs": [ { "msg_index": "0", "success": true, "log": "" } ],"gas_wanted":"200000", "gas_used": "41510", "tags": [ { "key": "action", "value": "buy_name" } ]}

# Set the data for that name that jack just bought
# NOTE: Be sure to specialize this request for your specific environment, also the "owner" and "from" should be the same address
$ curl -XPUT -s http://localhost:1317/nameservice/names --data-binary '{"base_req":{"from":"jack","password":"foobarbaz","chain_id":"namechain","sequence":"3","account_number":"0"},"name":"jack1.id","value":"8.8.4.4","owner":"cosmos127qa40nmq56hu27ae263zvfk3ey0tkapwk0gq6"}'
$ curl -XPUT -s http://localhost:1317/nameservice/names --data-binary '{"base_req":{"from":"'$(nscli keys show jack -a)'","chain_id":"namechain"},"name":"jack1.id","value":"8.8.4.4","owner":"'$(nscli keys show jack -a)'"}' > unsignedTx.json
# > {"check_tx":{"gasWanted":"200000","gasUsed":"1242"},"deliver_tx":{"log":"Msg 0: ","gasWanted":"200000","gasUsed":"1352","tags":[{"key":"YWN0aW9u","value":"c2V0X25hbWU="}]},"hash":"B4DF0105D57380D60524664A2E818428321A0DCA1B6B2F091FB3BEC54D68FAD7","height":"26"}

# Again we need to sign and broadcast
nscli tx sign unsignedTx.json --from jack --offline --chain-id namechain --sequence 2 --account-number 0 > signedTx.json
nscli tx broadcast signedTx.json

# Query the value for the name jack just set
$ curl -s http://localhost:1317/nameservice/names/jack1.id
# 8.8.4.4
Expand All @@ -45,8 +56,13 @@ $ curl -s http://localhost:1317/nameservice/names/jack1.id/whois
# > {"value":"8.8.8.8","owner":"cosmos127qa40nmq56hu27ae263zvfk3ey0tkapwk0gq6","price":[{"denom":"STAKE","amount":"10"}]}

# Alice buys name from jack
$ curl -XPOST -s http://localhost:1317/nameservice/names --data-binary '{"base_req":{"from":"alice","password":"foobarbaz","chain_id":"namechain","sequence":"1","account_number":"1"},"name":"jack1.id","amount":"10nametoken","buyer":"cosmos1h7ztnf2zkf4558hdxv5kpemdrg3tf94hnpvgsl"}'
# > {"check_tx":{"gasWanted":"200000","gasUsed":"1264"},"deliver_tx":{"log":"Msg 0: ","gasWanted":"200000","gasUsed":"4509","tags":[{"key":"YWN0aW9u","value":"YnV5X25hbWU="}]},"hash":"81A371392B52F703266257D524538085F8C749EE3CBC1C579873632EFBAFA40C","height":"70"}
$ curl -XPOST -s http://localhost:1317/nameservice/names --data-binary '{"base_req":{"from":"'$(nscli keys show alice -a)'","chain_id":"namechain"},"name":"jack1.id","amount":"10nametoken","buyer":"'$(nscli keys show alice -a)'"}' > unsignedTx.json

# And a final time sign and broadcast
# NOTE: The account number has changed to 1 and the sequence is now 2, according to the query of alice's account
nscli tx sign unsignedTx.json --from alice --offline --chain-id namechain --sequence 2 --account-number 1 > signedTx.json
nscli tx broadcast signedTx.json
# > { "height": "1515", "txhash": "C9DCC423E10E7E5E40A549057A4AA060DA6D6A885A394F6ED5C0E40AEE984A77", "logs": [ { "msg_index": "0", "success": true, "log": "" } ],"gas_wanted": "200000", "gas_used": "42375", "tags": [ { "key": "action", "value": "buy_name" } ]}
```

### Request Schemas:
Expand All @@ -56,10 +72,7 @@ $ curl -XPOST -s http://localhost:1317/nameservice/names --data-binary '{"base_r
{
"base_req": {
"name": "string",
"password": "string",
"chain_id": "string",
"sequence": "number",
"account_number": "number",
"gas": "string,not_req",
"gas_adjustment": "string,not_req",
},
Expand All @@ -74,10 +87,7 @@ $ curl -XPOST -s http://localhost:1317/nameservice/names --data-binary '{"base_r
{
"base_req": {
"name": "string",
"password": "string",
"chain_id": "string",
"sequence": "number",
"account_number": "number",
"gas": "string,not_req",
"gas_adjustment": "strin,not_reqg"
},
Expand Down

0 comments on commit 375c7cd

Please sign in to comment.