Skip to content

Commit

Permalink
TxBuilder: Update message protos (#76)
Browse files Browse the repository at this point in the history
* chore: adapt builder to new models

* chore: update autogenerated stuff

* chore: update docs

* feat: introduce sane defaults for stake/unstake

* chore: fix annoying errors

* fix: proto messages encoding

* fix: update messages keys for unjail/unstake

* chore: version bump

* chore: version bump

Co-authored-by: Enrique Ortiz <[email protected]>
  • Loading branch information
crisog and Evalir authored Aug 5, 2022
1 parent 8e25689 commit 00e85a5
Show file tree
Hide file tree
Showing 17 changed files with 629 additions and 343 deletions.
2 changes: 1 addition & 1 deletion packages/abstract-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pokt-foundation/pocketjs-abstract-provider",
"version": "1.2.0",
"version": "2.1.0",
"description": "Abstract provider for all other providers to inherit",
"type": "module",
"source": "src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/isomorphic-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pokt-foundation/pocketjs-isomorphic-provider",
"version": "1.2.0",
"version": "2.1.0",
"description": "",
"type": "module",
"source": "src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pokt-foundation/pocketjs-provider",
"version": "1.2.0",
"version": "2.1.0",
"description": "",
"type": "module",
"source": "src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/relayer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pokt-foundation/pocketjs-relayer",
"version": "1.2.0",
"version": "2.1.0",
"description": "Slim relayer client for the Pocket Network v0 Protocol",
"type": "module",
"source": "src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/signer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pokt-foundation/pocketjs-signer",
"version": "1.2.0",
"version": "2.1.0",
"description": "Signer for Pocket Network V0 accounts",
"type": "module",
"source": "src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/transaction-builder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pokt-foundation/pocketjs-transaction-builder",
"version": "1.2.0",
"version": "2.1.0",
"description": "Transaction manager and utilties for the Pocket Network protocol",
"type": "module",
"source": "src/index.ts",
Expand Down
24 changes: 20 additions & 4 deletions packages/transaction-builder/src/abstract-tx-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,34 +110,50 @@ export abstract class AbstractBuilder {
/**
* Adds a NodeStake TxMsg for this transaction
* @param {string} nodePubKey - Node Public key
* @param {string} outputAddress - The address that the coins will be sent to when the node is unstaked
* @param {string[]} chains - Network identifier list to be serviced by this node
* @param {string} amount - the amount to stake, must be greater than or equal to 1 POKT
* @param {URL} serviceURL - Node service url
* @returns {MsgProtoNodeStakeTx} - The unsigned Node Stake message.
*/
abstract nodeStake({
nodePubKey,
outputAddress,
chains,
amount,
serviceURL,
}: {
nodePubKey: string
outputAddress: string
chains: string[]
amount: string
serviceURL: URL
}): MsgProtoNodeStakeTx

/**
* Adds a MsgBeginUnstake TxMsg for this transaction
* @param {string} address - Address of the Node to unstake for
* @param {string} nodeAddress - Address of the Node to unstake for
* @param {string} signerAddress - The address that the coins will be sent to when the node is unstaked. Must be the same address entered when the node was staked
* @returns {MsgProtoNodeUnstake} - The unsigned Node Unstake message.
*/
abstract nodeUnstake(address: string): MsgProtoNodeUnstake
abstract nodeUnstake({
nodeAddress,
signerAddress,
}: {
nodeAddress?: string
signerAddress?: string
}): MsgProtoNodeUnstake

/**
* Adds a MsgUnjail TxMsg for this transaction
* @param {string} address - Address of the Node to unjail
* @param {string} nodeAddress - Address of the Node to unjail
* @returns {MsgProtoNodeUnjail} - The unsigned Node Unjail message.
*/
abstract nodeUnjail(address: string): MsgProtoNodeUnjail
abstract nodeUnjail({
nodeAddress,
signerAddress,
}: {
nodeAddress?: string
signerAddress?: string
}): MsgProtoNodeUnjail
}
1 change: 0 additions & 1 deletion packages/transaction-builder/src/models/msgs/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './msg-proto-app-stake'
export * from './msg-proto-app-unjail'
export * from './msg-proto-app-unstake'
export * from './msg-proto-node-stake'
export * from './msg-proto-node-unjail'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Buffer } from 'buffer'
import { MsgProtoNodeStake } from './../proto/generated/tx-signer'
import { MsgProtoNodeStake8 } from './../proto/generated/tx-signer'
import { Any } from '../proto/generated/google/protobuf/any'
import { TxMsg } from './tx-msg'

Expand All @@ -9,11 +9,12 @@ const MINIMUM_STAKE_AMOUNT = 15000000000
* Model representing a MsgNodeStake to stake as an Node in the Pocket Network
*/
export class MsgProtoNodeStakeTx extends TxMsg {
public readonly KEY: string = '/x.nodes.MsgProtoStake'
public readonly AMINO_KEY: string = 'pos/MsgStake'
public readonly KEY: string = '/x.nodes.MsgProtoStake8'
public readonly AMINO_KEY: string = 'pos/8.0MsgStake'
public readonly DEFAULT_PORT: string = '443'
public readonly DEFAULT_PROTOCOL: string = 'https:'
public readonly pubKey: Buffer
public readonly outputAddress: Buffer
public readonly chains: string[]
public readonly amount: string
public readonly serviceURL: URL
Expand All @@ -26,12 +27,14 @@ export class MsgProtoNodeStakeTx extends TxMsg {
*/
constructor(
pubKey: string,
outputAddress: string,
chains: string[],
amount: string,
serviceURL: URL
) {
super()
this.pubKey = Buffer.from(pubKey, 'hex')
this.outputAddress = Buffer.from(outputAddress, 'hex')
this.chains = chains
this.amount = amount
this.serviceURL = serviceURL
Expand Down Expand Up @@ -78,6 +81,7 @@ export class MsgProtoNodeStakeTx extends TxMsg {
type: this.AMINO_KEY,
value: {
chains: this.chains,
output_address: this.outputAddress.toString('hex'),
public_key: {
type: 'crypto/ed25519_public_key',
value: this.pubKey.toString('hex'),
Expand All @@ -99,11 +103,12 @@ export class MsgProtoNodeStakeTx extends TxMsg {
Chains: this.chains,
value: this.amount,
ServiceUrl: this.getParsedServiceURL(),
OutAddress: this.outputAddress,
}

return Any.fromJSON({
typeUrl: this.KEY,
value: Buffer.from(MsgProtoNodeStake.encode(data).finish()).toString(
value: Buffer.from(MsgProtoNodeStake8.encode(data).finish()).toString(
'base64'
),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { Buffer } from 'buffer'
import { MsgNodeUnjail } from '../proto/generated/tx-signer'
import { MsgNodeUnjail8 } from '../proto/generated/tx-signer'
import { Any } from '../proto/generated/google/protobuf/any'
import { TxMsg } from './tx-msg'

/**
* Model representing a MsgNodeUnjail to unjail as an Node in the Pocket Network
*/
export class MsgProtoNodeUnjail extends TxMsg {
public readonly KEY: string = '/x.nodes.MsgUnjail'
public readonly AMINO_KEY: string = 'pos/MsgUnjail'
public readonly address: string
public readonly KEY: string = '/x.nodes.MsgUnjail8'
public readonly AMINO_KEY: string = 'pos/8.0MsgUnjail'
public readonly nodeAddress: string
public readonly signerAddress: string

/**
* @param {string} address - Address value
* @param {string} nodeAddress - Node address to be unjailed
* @param {string} signerAddress - Signer address (who triggered the unjail)
*/
public constructor(address: string) {
public constructor(nodeAddress: string, signerAddress: string) {
super()
this.address = address
this.nodeAddress = nodeAddress
this.signerAddress = signerAddress
}
/**
* Converts an Msg Object to StdSignDoc
Expand All @@ -27,7 +30,8 @@ export class MsgProtoNodeUnjail extends TxMsg {
return {
type: this.AMINO_KEY,
value: {
address: this.address,
address: this.nodeAddress,
signer_address: this.signerAddress,
},
}
}
Expand All @@ -38,11 +42,14 @@ export class MsgProtoNodeUnjail extends TxMsg {
* @memberof MsgNodeUnjail
*/
public toStdTxMsgObj(): any {
const data = { ValidatorAddr: Buffer.from(this.address, 'hex') }
const data = {
ValidatorAddr: Buffer.from(this.nodeAddress, 'hex'),
Signer: Buffer.from(this.signerAddress, 'hex'),
}

return Any.fromJSON({
typeUrl: this.KEY,
value: Buffer.from(MsgNodeUnjail.encode(data).finish()).toString(
value: Buffer.from(MsgNodeUnjail8.encode(data).finish()).toString(
'base64'
),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { Buffer } from 'buffer'
import { MsgBeginNodeUnstake } from './../proto/generated/tx-signer'
import { MsgBeginNodeUnstake8 } from './../proto/generated/tx-signer'
import { Any } from '../proto/generated/google/protobuf/any'
import { TxMsg } from './tx-msg'
/**
* Model representing a MsgNodeStake to unstake as an Node in the Pocket Network
*/
export class MsgProtoNodeUnstake extends TxMsg {
public readonly KEY: string = '/x.nodes.MsgBeginUnstake'
public readonly AMINO_KEY: string = 'pos/MsgBeginUnstake'
public readonly KEY: string = '/x.nodes.MsgBeginUnstake8'
public readonly AMINO_KEY: string = 'pos/8.0MsgBeginUnstake'
public readonly nodeAddress: string
public readonly signerAddress: string

/**
* @param {string} nodeAddress - Node address
*/
public constructor(nodeAddress: string) {
public constructor(nodeAddress: string, signerAddress: string) {
super()
this.nodeAddress = nodeAddress
this.signerAddress = signerAddress
}
/**
* Converts an Msg Object to StdSignDoc
Expand All @@ -26,6 +28,7 @@ export class MsgProtoNodeUnstake extends TxMsg {
return {
type: this.AMINO_KEY,
value: {
signer_address: this.signerAddress,
validator_address: this.nodeAddress,
},
}
Expand All @@ -37,11 +40,14 @@ export class MsgProtoNodeUnstake extends TxMsg {
* @memberof MsgNodeUnstake
*/
public toStdTxMsgObj(): any {
const data = { Address: Buffer.from(this.nodeAddress, 'hex') }
const data = {
Address: Buffer.from(this.nodeAddress, 'hex'),
Signer: Buffer.from(this.signerAddress, 'hex'),
}

return Any.fromJSON({
typeUrl: this.KEY,
value: Buffer.from(MsgBeginNodeUnstake.encode(data).finish()).toString(
value: Buffer.from(MsgBeginNodeUnstake8.encode(data).finish()).toString(
'base64'
),
})
Expand Down
Loading

0 comments on commit 00e85a5

Please sign in to comment.