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

modules/coin/rest: implemented doCreateRole #208

Merged
merged 3 commits into from
Aug 18, 2017
Merged

modules/coin/rest: implemented doCreateRole #208

merged 3 commits into from
Aug 18, 2017

Conversation

odeke-em
Copy link
Collaborator

@odeke-em odeke-em commented Aug 3, 2017

Implements doCreateRole

    $ curl -X POST http://localhost:8998/build/create_role --data '{"role":
    "abcdef", "sigs": 1, "signers": [{"addr":
    "4FF759D47C81754D8F553DCCAC8651D0AF74C7F9", "app": "role"}]}'
    HTTP/1.1 200 OK
    Content-Type: application/json
    Date: Fri, 04 Aug 2017 05:49:19 GMT
    Content-Length: 233
    
    {
      "type": "role/create",
      "data": {
        "role": "616263646566",
        "min_sigs": 1,
        "signers": [
          {
            "chain": "",
            "app": "role",
            "addr": "4FF759D47C81754D8F553DCCAC8651D0AF74C7F9"
          }
        ]
      }
    }

Updates #200

@odeke-em
Copy link
Collaborator Author

odeke-em commented Aug 4, 2017

Alright, now CLI tests remaining.

@ethanfrey
Copy link
Contributor

Cool, added functionality.

Two main points, I could add them to code, but easier here:

  1. Please parse the input role name as hex. I will fix the cli to do the same (today?)
  2. Please wrap the role with all the middleware (fee, chain, sigs) as with /build/send. All tx without this wrapping are kind of useless as they cannot be signed and will be rejected by the server upon post. (maybe you want to make a function to do this)?

@odeke-em
Copy link
Collaborator Author

odeke-em commented Aug 4, 2017

Thanks for the notes @ethanfrey. In regards to:

  1. I see you already implemented that, I've rebased
  2. Unfortunately there isn't a fee associated with a role. I can only wrap it with: chain + signers.

@odeke-em
Copy link
Collaborator Author

odeke-em commented Aug 4, 2017

Alright, I've updated the PR, PTAL.

@odeke-em
Copy link
Collaborator Author

odeke-em commented Aug 8, 2017

After this PR is merged into unstable, there is another coming up on branch https://github.com/orijtech/basecoin/tree/query_role and that should conclude #200 or at least for the listed tasks.

Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but the create role handler belongs in modules/roles/rest

@odeke-em
Copy link
Collaborator Author

odeke-em commented Aug 8, 2017

Thanks @ethanfrey, yeah that's a brain fart on my part, I'll move that code.

@odeke-em
Copy link
Collaborator Author

odeke-em commented Aug 8, 2017

Updated @ethanfrey, PTAL!

@odeke-em odeke-em mentioned this pull request Aug 8, 2017
"github.com/tendermint/tmlibs/common"
)

type RoleInput struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a comment for the public struct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good plan, thanks for letting me know. I'll update this in a second.


// mux.Router registrars

// RegisterQueryAccount is a mux.Router handler that exposes GET
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment appears stale. Should be RegisterCreateRole and route is /build/create_role

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thank you, updating it.

tx = roles.NewCreateRoleTx(parsedRole, ri.MinimumSigners, ri.Signers)

// 3. ChainTx
tx = base.NewChainTx(commands.GetChainID(), 0, tx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not thrilled about calls to commands package all over. Think we need to revisit approach. It's certainly convenient and not that bad, just somewhat striking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree, perhaps we need a refactor in a few rounds. I think we had coupled all the functionality with the CLI(for which all these libraries had been built for) and in order to spin up the rest server (a quick job) we haven't been able to dissect and change it up.

@@ -24,11 +24,17 @@ Route | Method | Completed | Description
/sign|POST|✔️|Sign a transaction
/tx|POST|✖️|Post a transaction to the blockchain
/seeds/status|GET|✖️|Returns the information on the last seed
/build/create_role|POST|✔️|Creates a role. Please note that the role MUST be valid hex for example instead of sending "role", send its hex encoded equivalent "726f6c65"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not surprised to see this, but it doesn't make the best experience. Can we do something about it or is this a deep issue ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we changed this up in tendermint/basecoin@f2adf36 and the rational is that using hex makes sending content "more secure"/obfuscated as opposed to just sending a string, cc @ethanfrey.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ok. I'll wait to here from frey on this one. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we use hex identifiers everywhere and there was confusion writing tests with it not being hex. Then in a discussion, someone mentioned it was not good to use strings ("cosmos-devs") but rather force hex bytes which would generally be chosen with no human significance, and not leak information.

Seems easier and no need to use human-readable strings in the API, although one could build that on top, if so desired.

@odeke-em
Copy link
Collaborator Author

Thank you @ebuchman for the review, I've updated the feedback in tendermint/basecoin@d5b63ab, PTAL!

@ebuchman
Copy link
Member

Great!

* Note: Role must be a hex string, as enforced in tests/rest/cli.sh

```shell
$ curl -X POST http://localhost:8998/build/create_role --data \
'{
  "role":"DEADBEEF", "seq": 1,
  "min_sigs": 1,
  "signers": [{
    "addr": "4FF759D47C81754D8F553DCCAC8651D0AF74C7F9", "app": "role"
  }]
}'
```

```HTTP
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 08 Aug 2017 19:15:13 GMT
Content-Length: 387

{
  "type": "chain/tx",
  "data": {
    "chain_id": "test_chain_id",
    "expires_at": 0,
    "tx": {
      "type": "role/create",
      "data": {
        "role": "DEADBEEF",
        "min_sigs": 1,
        "signers": [
          {
            "chain": "",
            "app": "role",
            "addr": "4FF759D47C81754D8F553DCCAC8651D0AF74C7F9"
          }
        ]
      }
    }
  }
}
```

Updates #200
@ethanfrey ethanfrey merged commit 7b3fde4 into cosmos:unstable Aug 18, 2017
@odeke-em odeke-em deleted the build_create branch August 29, 2019 02:39
ParthDesai pushed a commit to ChorusOne/cosmos-sdk that referenced this pull request Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants