Skip to content

Commit

Permalink
Wallet msgs (#373)
Browse files Browse the repository at this point in the history
* Adds support to craft supported msg types
* Added docs and custom validation for easy usage

closes: #355
  • Loading branch information
minxylynx authored Jun 29, 2022
1 parent eeef539 commit 9649844
Show file tree
Hide file tree
Showing 43 changed files with 1,341 additions and 87 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features
* Updated Provenance proto set to 1.11.0 #371
* Add Support for Tx Msg building #355
* Now supports building Tx msgs through API
* POST `/api/v3/gov/types/supported` - Gives list of proposal types supported for governance msgs
* POST `/api/v3/gov/submit/{type}` - Crafts a Submit Proposal msg from the given data
* POST `/api/v3/gov/deposit` - Crafts a Deposit msg
* POST `/api/v3/gov/vote` - Crafts a Vote msg
* POST `/api/v3/staking/delegate` - Crafts a Delegate msg
* POST `/api/v3/staking/redelegate` - Crafts a Redelegate msg
* POST `/api/v3/staking/undelegate` - Crafts an Undelegate msg
* POST `/api/v3/staking/withdraw_rewards` - Crafts a Withdraw Rewards msg
* POST `/api/v3/staking/withdraw_commission` - Crafts a Withdraw Commission msg
* POST `/api/v2/accounts/send` - Crafts a Send msg
* Validations included to allow for better support
* Docs included to help with usage

### Improvements
* Added Validation message collection to allow for multiple validations at once #355

## [v4.3.1](https://github.com/provenance-io/explorer-service/releases/tag/v4.3.1) - 2022-06-24
### Release Name: James of Ireland
Expand All @@ -61,7 +78,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes
* Fixed the Validator missed block count
* Added else case for IBC Recvs where the effected Recv is in the same tx as an uneffected Recv, which makes the block error out
* Added VotWeighted msg type to `getGovMsgDetail()` function
* Added VoteWeighted msg type to `getGovMsgDetail()` function
* Fixed how addresses were being associated with txs

### Data
Expand Down
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ subprojects {
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict", "-Xopt-in=kotlin.RequiresOptIn")
freeCompilerArgs = listOf(
"-Xjsr305=strict",
"-Xopt-in=kotlin.RequiresOptIn",
"-Xopt-in=kotlin.contracts.ExperimentalContracts"
)
jvmTarget = "11"
languageVersion = "1.5"
apiVersion = "1.5"
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ object Versions {
const val Grpc = "1.40.1"
const val ProvProto = "1.11.0"
const val Postgres = "42.2.23"
const val Protobuf = "3.19.1"

// Testing
const val Jupiter = "5.7.1"
Expand Down Expand Up @@ -92,6 +93,7 @@ object Libraries {
// Protobuf
const val GrpcNetty = "io.grpc:grpc-netty:${Versions.Grpc}"
const val ProvenanceProto = "io.provenance:proto-kotlin:${Versions.ProvProto}"
const val ProtobufKotlin = "com.google.protobuf:protobuf-kotlin:${Versions.Protobuf}"

// Spring
const val SpringBootDevTools = "org.springframework.boot:spring-boot-devtools:${Versions.SpringBoot}"
Expand Down
40 changes: 20 additions & 20 deletions docker/docker-compose-db.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
version: '3.5'
services:
explorer-postgres:
image: postgres:13.2
container_name: postgres-local-testnet
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password1
ports:
- 5432:5432
volumes:
- ./db-init:/docker-entrypoint-initdb.d/ # inits the db with username/password
- pg-local-testnet:/var/lib/postgresql/data

volumes:
pg-local-testnet:


#services:
# explorer-postgres:
# image: postgres:13.2
# container_name: postgres-local-mainnet
# container_name: postgres-local-testnet
# environment:
# - POSTGRES_USER=postgres
# - POSTGRES_PASSWORD=password1
# ports:
# - 5432:5432
# volumes:
# - ./db-init:/docker-entrypoint-initdb.d/ # inits the db with username/password
# - pg-local-mainnet:/var/lib/postgresql/data
# - pg-local-testnet:/var/lib/postgresql/data
#
#volumes:
# pg-local-mainnet:
# pg-local-testnet:


services:
explorer-postgres:
image: postgres:13.2
container_name: postgres-local-mainnet
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password1
ports:
- 5432:5432
volumes:
- ./db-init:/docker-entrypoint-initdb.d/ # inits the db with username/password
- pg-local-mainnet:/var/lib/postgresql/data

volumes:
pg-local-mainnet:
36 changes: 36 additions & 0 deletions docs/msgs/Account Msgs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Account Msgs
* [Delegate](#delegate)
* [Redelegate](#redelegate)
* [Undelegate](#undelegate)
* [Withdraw Rewards](#withdraw-rewards)
* [Withdraw Commission](#withdraw-commission)


## Send
To craft a MsgDelegate, use `/api/v3/accounts/send`
Example CURL request:
```shell
curl -X POST "http://localhost:8612/api/v2/accounts/send" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "authorization: Bearer eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ==.eyJzdWIiOiJBMFBMcWdKQ3BaeklXK0xNckFzT003bFpXM2RMejRtaE00YnVWTmk0K2pnaSIsImlzcyI6InByb3ZlbmFuY2UuaW8iLCJpYXQiOjE2NTU0MDg2NjIsImV4cCI6MTY1NTQ5NTA2MiwiYWRkciI6InBiMTk0OWFlZWpheWZzNHNydGw4c2M2NzJoMm0wM3hhcno0NnVuejRxIn0=.Tbt2Qg62qoFhW959UUPL6wJcGc1tERfOaQhPTmn4FgFiG1+WuAZbQzQrFmtgJlqRQbAJZ3QF08UVJ5xiJi5R7A==" \
--data-raw '{"from":"pb1949aeejayfs4srtl8sc672h2m03xarz46unz4q","funds":[{"amount":"100","denom":"nhash"}],"to":"pb1mcyukv73v57jm2cq48p6y666kqjed8suyphshq"}' \
--compressed
```

For the `request` portion, use the following structure:
```json
{
"from": "string",
"funds": [
{
"amount": "string",
"denom": "string"
}
],
"to": "string"
}
```
* `from` - The same address of the signer
* `to` - A valid standard address; must be different that the `from` address
* `amount` - A list of funds to send, in valid denoms
34 changes: 34 additions & 0 deletions docs/msgs/Crafting Msgs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Crafting Msgs for Txs

Explorer service now supports crafting specific msgs through APIs. This does not submit the msg, only provides validation
and formatting/packing.

* [Governance Msgs](Gov%20Msgs.md)
* [Staking Msgs](Staking%20Msgs.md)
* [Account Msgs](Account%20Msgs.md)

After validating and building the basic msg, the API will pack the msg into the `TxBody` object type, and return the following:
```json
{
"json": {
"messages": [
{
"@type": "/cosmos.gov.v1beta1.MsgVote",
"proposalId": "36",
"voter": "pb1949aeejayfs4srtl8sc672h2m03xarz46unz4q",
"option": "VOTE_OPTION_YES"
}
]
},
"base64": [
"ChsvY29zbW9zLmdvdi52MWJldGExLk1zZ1ZvdGUSLwgkEilwYjE5NDlhZWVqYXlmczRzcnRsOHNjNjcyaDJtMDN4YXJ6NDZ1bno0cRgB"
]
}
```
* `json` - A list of readable msgs to show what was built
* `base64` - The list of built msgs encoded into base64 for proper Tx usage

The `json` is used to display to the user prior to signing, so they see what was built exactly. The `base64` is used to
build the Tx properly for submission.


175 changes: 175 additions & 0 deletions docs/msgs/Gov Msgs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Governance Msgs
* [Submit Proposal](#submit-proposal)
+ [Supported Proposal Types](#supported-proposal-types)
+ TEXT
* PARAMETER_CHANGE
* SOFTWARE_UPGRADE
* CANCEL_SOFTWARE
* STORE_CODE
* INSTANTIATE_CONTRACT
+ [Submit Proposal Crafting Request](#submit-proposal-crafting-request)
* [Vote and WeightedVote](#vote-and-weightedvote)
* [Deposit](#deposit)


## Submit Proposal
### Supported Proposal Types
There is an API to fetch the supported types and their content object structure: `/api/v3/gov/types/supported`
This will give you the enum value mapped to the content structure to be used when submitting a proposal msg creation
request.
```json
{
"TEXT": {},
"PARAMETER_CHANGE": {
"changes": [
{
"subspace": "param_space",
"key": "param_key",
"value": "param_value"
},
{
"subspace": "attribute",
"key": "not_a_real_key",
"value": "blah"
}
]
},
"SOFTWARE_UPGRADE": {
"name": "Test Name",
"height": 1000087,
"info": "This is info for the upgrade."
},
"CANCEL_UPGRADE": {},
"STORE_CODE": {
"runAs": "run as address",
"accessConfig": {
"type": "ACCESS_TYPE_EVERYBODY",
"address": "Only set to an address if ACCESS_TYPE_ONLY_ADDRESS, else null"
}
},
"INSTANTIATE_CONTRACT": {
"runAs": "run as address",
"admin": "admin address or null",
"codeId": 140,
"label": "Unique label for easy identification",
"msg": "stringified JSON object for msg data to be used by the contract",
"funds": [
{
"amount": "100",
"denom": "some_denom"
}
]
}
}
```

### Submit Proposal Crafting Request
To craft a MsgSubmitProposal, use `/api/v3/gov/submit/{type}`
Example CURL request:
```shell
curl -X POST 'http://localhost:8612/api/v3/gov/submit/{PROPOSAL_TYPE}' \
-H 'accept: application/json' \
-H 'authorization: {JWT_TOKEN}' \
-H 'content-type: multipart/form-data' \
-F 'request={ "content": {THIS IS THE CORRESPONDING OBJECT STRUCTURE STRINGIFIED}, "description": "Test", "initialDeposit": [ { "amount": "1000", "denom": "nhash" } ], "submitter": "THIS IS YOUR SUBMITTING ADDRESS", "title": "Test proposal" };type=application/json' \
-F 'wasmFile=@{THIS IS THE PATH TO YOUR .wasm FILE};type=application/octet-stream' \ <------------ EXCLUDE IF NOT SUBMITTING A .wasm FILE
--compressed
```

For the `request` portion, use the following structure:
```json
{
"content": "string",
"description": "string",
"initialDeposit": [
{
"amount": "string",
"denom": "string"
}
],
"submitter": "string",
"title": "string"
}
```
* `content` - This is a stringified JSON object as mapped to the PROPOSAL_TYPE enum values coming from the [Supported Types API](#supported-proposal-types)
* `description` - The description for the proposal
* `initialDeposit` - Can be an empty list if no deposit is attached to the proposal request; Should be in denom `nhash`
* `submitter` - The same address of the signer
* `title` - The title of the proposal

Ensure the `request` is typed to `type=application/json`.

For the `wasmFile` portion, ensure you have the path to the .wasm file, and it is typed to `type=application/octet-stream`.


## Vote and WeightedVote
To craft a MsgVote or MsgWeightedVote, use `/api/v3/gov/vote`
Example CURL request:
```shell
curl -X POST 'http://localhost:8612/api/v3/gov/vote' \
-H 'accept: application/json' \
-H 'authorization: Bearer eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ==.eyJzdWIiOiJBMFBMcWdKQ3BaeklXK0xNckFzT003bFpXM2RMejRtaE00YnVWTmk0K2pnaSIsImlzcyI6InByb3ZlbmFuY2UuaW8iLCJpYXQiOjE2NTU0MDg2NjIsImV4cCI6MTY1NTQ5NTA2MiwiYWRkciI6InBiMTk0OWFlZWpheWZzNHNydGw4c2M2NzJoMm0wM3hhcno0NnVuejRxIn0=.Tbt2Qg62qoFhW959UUPL6wJcGc1tERfOaQhPTmn4FgFiG1+WuAZbQzQrFmtgJlqRQbAJZ3QF08UVJ5xiJi5R7A==' \
-H 'content-type: application/json' \
--data-raw '{"proposalId":36,"voter":"pb1949aeejayfs4srtl8sc672h2m03xarz46unz4q","votes":[{"option":"VOTE_OPTION_YES","weight":100}]}' \
--compressed
```

For the `request` portion, use the following structure:
```json
{
"proposalId": 0,
"voter": "string",
"votes": [
{
"option": "UNRECOGNIZED",
"weight": 0
}
]
}
```
* `proposalId` - A valid proposal ID; must be in Voting Period
* `voter` - The same address of the signer
* `votes` - A list of votes with weights; The weights must add up to 100
* Supported vote options come from the Gov.VoteOption proto enum
* VOTE_OPTION_YES
* VOTE_OPTION_ABSTAIN
* VOTE_OPTION_NO
* VOTE_OPTION_NO_WITH_VETO

If there is a single vote in the `votes` array, a MsgVote will be crafted. Otherwise, a MsgWeightedVote will be crafted.

## Deposit
To craft a MsgDeposit, use `/api/v3/gov/deposit`
Example CURL request:
```shell
curl -X POST 'http://localhost:8612/api/v3/gov/deposit' \
-H 'accept: application/json' \
-H 'authorization: Bearer eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ==.eyJzdWIiOiJBMFBMcWdKQ3BaeklXK0xNckFzT003bFpXM2RMejRtaE00YnVWTmk0K2pnaSIsImlzcyI6InByb3ZlbmFuY2UuaW8iLCJpYXQiOjE2NTU0MDg2NjIsImV4cCI6MTY1NTQ5NTA2MiwiYWRkciI6InBiMTk0OWFlZWpheWZzNHNydGw4c2M2NzJoMm0wM3hhcno0NnVuejRxIn0=.Tbt2Qg62qoFhW959UUPL6wJcGc1tERfOaQhPTmn4FgFiG1+WuAZbQzQrFmtgJlqRQbAJZ3QF08UVJ5xiJi5R7A==' \
-H 'content-type: application/json' \
--data-raw '{"deposit":[{"amount":"10000","denom":"nhash"}],"depositor":"pb1949aeejayfs4srtl8sc672h2m03xarz46unz4q","proposalId":36}' \
--compressed
```

For the `request` portion, use the following structure:
```json
{
"deposit": [
{
"amount": "string",
"denom": "string"
}
],
"depositor": "string",
"proposalId": 0
}
```
* `proposalId` - A valid proposal ID; must be in Deposit Period or Voting Period
* `depositor` - The same address of the signer
* `deposit` - A list of amounts to be used as a deposit against the proposal; typically the denom is `nhash`, with at
least one amount greater than zero






Loading

0 comments on commit 9649844

Please sign in to comment.