Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

feat: wip create message validator #40

Closed
wants to merge 1 commit into from
Closed
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
79 changes: 79 additions & 0 deletions packages/eip712/src/messages/validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
export const MSG_DELEGATE_TYPES = {
TypeDescription: [
{ name: 'moniker', type: 'string' },
{ name: 'identity', type: 'string' },
{ name: 'website', type: 'string' },
{ name: 'security_contact', type: 'string' },
{ name: 'details', type: 'string' },
],
TypeCommission: [
{ name: 'rate', type: 'string' },
{ name: 'max_rate', type: 'string' },
{ name: 'max_change_rate', type: 'string' },
],
TypePubkey: [
{ name: 'type', type: 'string' },
{ name: 'value', type: 'TypePubkeyValue' },
],
MsgValue: [
{ name: 'description', type: 'TypeDescription' },
{ name: 'commission', type: 'TypeCommission' },
{ name: 'min_self_delegation', type: 'string' },
{ name: 'delegator_address', type: 'string' },
{ name: 'validator_address', type: 'string' },
{ name: 'pubkey', type: 'TypePubkey' },
{ name: 'value', type: 'TypeValue' },
],
TypePubkeyValue: [{ name: 'key', type: 'uint8' }],
TypeValue: [
{ name: 'denom', type: 'string' },
{ name: 'amount', type: 'string' },
],
}

export function createMsgCreateValidator(
validatorDescription: {
moniker: string
identity: string
website: string
securityContact: string
details: string
},
validatorCommission: {
rate: string
maxRate: string
maxChangeRate: string
},
minSelfDelegation: string,
delegatorAddress: string,
validatorAddress: string,
amount: string,
denom: string,
pubkey: Uint8Array,
) {
return {
type: 'cosmos-sdk/MsgCreateValidator',
value: {
amount: {
amount,
denom,
},
delegator_address: delegatorAddress,
validator_address: validatorAddress,
validator_description: {
moniker: validatorDescription.moniker,
identity: validatorDescription.identity,
website: validatorDescription.website,
security_contract: validatorDescription.securityContact,
details: validatorDescription.details,
},
validator_commission: {
rate: validatorCommission.rate,
max_rate: validatorCommission.maxRate,
max_change_rate: validatorCommission.maxChangeRate,
},
min_self_delegation: minSelfDelegation,
pubkey,
},
}
}
10 changes: 10 additions & 0 deletions packages/proto/src/messages/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Message } from 'google-protobuf'
import * as google from '../proto/google/protobuf/any'
import * as pubkey from '../proto/ethermint/crypto/v1/ethsecp256k1/keys'

export interface MessageGenerated {
message: Message
Expand All @@ -12,3 +13,12 @@ export function createAnyMessage(msg: MessageGenerated) {
value: msg.message.serializeBinary(),
})
}

export function createPubKey(key: Uint8Array) {
return {
path: '/ethermint.crypto.v1.ethsecp256k1.PubKey',
message: new pubkey.ethermint.crypto.v1.ethsecp256k1.PubKey({
key,
}),
}
}
59 changes: 59 additions & 0 deletions packages/proto/src/messages/validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as staking from '../proto/cosmos/staking/v1beta1/tx'
import * as stakingTypes from '../proto/cosmos/staking/v1beta1/staking'
import * as coin from '../proto/cosmos/base/v1beta1/coin'
import { createAnyMessage, createPubKey } from './utils'

export function createMsgCreateValidator(
validatorDescription: {
moniker: string
identity: string
website: string
securityContact: string
details: string
},
validatorCommission: {
rate: string
maxRate: string
maxChangeRate: string
},
minSelfDelegation: string,
delegatorAddress: string,
validatorAddress: string,
amount: string,
denom: string,
pubkey: Uint8Array,
) {
const commission = new stakingTypes.cosmos.staking.v1beta1.CommissionRates({
rate: validatorCommission.rate,
max_rate: validatorCommission.maxRate,
max_change_rate: validatorCommission.maxChangeRate,
})

const description = new stakingTypes.cosmos.staking.v1beta1.Description({
moniker: validatorDescription.moniker,
identity: validatorDescription.identity,
website: validatorDescription.website,
security_contact: validatorDescription.securityContact,
details: validatorDescription.details,
})

const value = new coin.cosmos.base.v1beta1.Coin({
denom,
amount,
})

const message = new staking.cosmos.staking.v1beta1.MsgCreateValidator({
min_self_delegation: minSelfDelegation,
delegator_address: delegatorAddress,
validator_address: validatorAddress,
value,
pubkey: createAnyMessage(createPubKey(pubkey)),
description,
commission,
})

return {
message,
path: 'cosmos.staking.v1beta1.MsgCreateValidator',
}
}
Empty file.