From b687b8334e651824f6a4371826b070ba56fda2fb Mon Sep 17 00:00:00 2001 From: neeraj Date: Wed, 13 Mar 2024 18:35:28 +0530 Subject: [PATCH] Remove unused code --- src/account.ts | 65 +--- src/index.ts | 73 +--- src/laconic-client.ts | 3 +- src/messages/auction.ts | 149 -------- src/messages/bond.ts | 590 ----------------------------- src/messages/registry.ts | 323 ---------------- src/messages/util.ts | 79 ---- src/registry-client.ts | 17 - src/schema/record.json | 5 - src/testing/helper.ts | 3 +- src/txbuilder.ts | 25 -- src/types/cerc/auction/message.ts | 10 + src/types/cerc/bond/message.ts | 39 ++ src/types/cerc/registry/message.ts | 26 ++ 14 files changed, 83 insertions(+), 1324 deletions(-) delete mode 100644 src/messages/auction.ts delete mode 100644 src/messages/bond.ts delete mode 100644 src/messages/registry.ts delete mode 100644 src/messages/util.ts delete mode 100644 src/schema/record.json delete mode 100644 src/txbuilder.ts diff --git a/src/account.ts b/src/account.ts index 6f6e1b2..2eec836 100644 --- a/src/account.ts +++ b/src/account.ts @@ -4,12 +4,8 @@ import * as ecc from 'tiny-secp256k1'; import * as bip39 from 'bip39'; import canonicalStringify from 'canonical-json'; import secp256k1 from 'secp256k1'; -import { utils } from 'ethers'; import { sha256 } from 'js-sha256'; -import { MessageTypes, signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util'; -import { Ripemd160 } from '@cosmjs/crypto'; -import { fromHex, toHex } from '@cosmjs/encoding'; -import { ethToEthermint } from '@tharsis/address-converter'; +import { toHex } from '@cosmjs/encoding'; import { encodeSecp256k1Pubkey } from '@cosmjs/amino'; import { DirectSecp256k1Wallet } from '@cosmjs/proto-signing'; @@ -19,14 +15,6 @@ const ACCOUNT_PREFIX = 'laconic'; const bip32 = BIP32Factory(ecc); -interface TypedMessageDomain { - name?: string; - version?: string; - chainId?: number; - verifyingContract?: string; - salt?: ArrayBuffer; -} - /** * Registry account. */ @@ -34,10 +22,7 @@ export class Account { _privateKey: Buffer; _publicKey!: Uint8Array; _encodedPubkey!: string; - _formattedCosmosAddress!: string; _registryPublicKey!: string; - _registryAddress!: string; - _ethAddress!: string; _wallet!: DirectSecp256k1Wallet; _address!: string; @@ -79,18 +64,10 @@ export class Account { return this._encodedPubkey; } - get formattedCosmosAddress () { - return this._formattedCosmosAddress; - } - get registryPublicKey () { return this._registryPublicKey; } - get registryAddress () { - return this._registryAddress; - } - get address () { return this._address; } @@ -112,19 +89,9 @@ export class Account { this._publicKey = secp256k1.publicKeyCreate(this._privateKey); this._encodedPubkey = encodeSecp256k1Pubkey(this._publicKey).value; - // 2. Generate eth address. - this._ethAddress = utils.computeAddress(this._publicKey); - - // 3. Generate cosmos-sdk formatted address. - this._formattedCosmosAddress = ethToEthermint(this._ethAddress); - - // 4. Generate registry formatted public key. + // Generate registry formatted public key. const publicKeyInHex = AMINO_PREFIX + toHex(account.pubkey); this._registryPublicKey = Buffer.from(publicKeyInHex, 'hex').toString('base64'); - - // 5. Generate registry formatted address. - let publicKeySha256 = sha256(Buffer.from(publicKeyInHex, 'hex')); - this._registryAddress = new Ripemd160().update(fromHex(publicKeySha256)).digest().toString(); } /** @@ -134,13 +101,6 @@ export class Account { return this._privateKey.toString('hex'); } - /** - * Get cosmos address. - */ - getCosmosAddress () { - return this._formattedCosmosAddress; - } - /** * Get record signature. */ @@ -160,25 +120,4 @@ export class Account { return Buffer.from(sigObj.signature); } - - /** - * Sign message. - */ - sign (message: any) { - assert(message); - const eipMessageDomain: any = message.eipToSign.domain; - - const signature = signTypedData({ - data: { - types: message.eipToSign.types as MessageTypes, - primaryType: message.eipToSign.primaryType, - domain: eipMessageDomain as TypedMessageDomain, - message: message.eipToSign.message as Record - }, - privateKey: this._privateKey, - version: SignTypedDataVersion.V4 - }); - - return signature; - } } diff --git a/src/index.ts b/src/index.ts index 935d3ba..c3ad8f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,22 +1,13 @@ import { sha256 } from 'js-sha256'; -import { generatePostBodyBroadcast, BroadcastMode } from '@tharsis/provider'; import { - Chain, - Sender, - Fee, MessageSendParams } from '@tharsis/transactions'; import { DeliverTxResponse, StdFee } from '@cosmjs/stargate'; import { RegistryClient } from './registry-client'; import { Account } from './account'; -import { createTransaction } from './txbuilder'; import { Util } from './util'; import { - createTxMsgAssociateBond, - createTxMsgDissociateBond, - createTxMsgDissociateRecords, - createTxMsgReAssociateRecords, MessageMsgAssociateBond, MessageMsgCancelBond, MessageMsgCreateBond, @@ -25,17 +16,16 @@ import { MessageMsgReAssociateRecords, MessageMsgRefillBond, MessageMsgWithdrawBond -} from './messages/bond'; +} from './types/cerc/bond/message'; import { MessageMsgDeleteName, MessageMsgSetAuthorityBond, - MessageMsgSetName, - NAMESERVICE_ERRORS -} from './messages/registry'; + MessageMsgSetName +} from './types/cerc/registry/message'; import { MessageMsgCommitBid, MessageMsgRevealBid -} from './messages/auction'; +} from './types/cerc/auction/message'; import { LaconicClient } from './laconic-client'; import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto2/cerc/bond/v1/tx'; import { Coin } from './proto2/cosmos/base/v1beta1/coin'; @@ -43,24 +33,6 @@ import { MsgSendResponse } from './proto2/cosmos/bank/v1beta1/tx'; export const DEFAULT_CHAIN_ID = 'laconic_9000-1'; -// Parse Tx response from cosmos-sdk. -export const parseTxResponse = (result: any, parseResponse?: (data: string) => any) => { - const { txhash: hash, height, ...txResponse } = result; - - if (parseResponse) { - txResponse.data = parseResponse(txResponse.data); - } - - txResponse.events.forEach((event:any) => { - event.attributes = event.attributes.map(({ key, value }: { key: string, value: string }) => ({ - key: Buffer.from(key, 'base64').toString('utf8'), - value: Buffer.from(value, 'base64').toString('utf8') - })); - }); - - return { hash, height, ...txResponse }; -}; - /** * Create an auction bid. */ @@ -87,12 +59,9 @@ export const createBid = async (chainId: string, auctionId: string, bidderAddres }; }; -export const isKeyValid = (key: string) => key && key.match(/^[0-9a-fA-F]{64}$/); - export class Registry { _endpoints: {[key: string]: string}; _chainID: string; - _chain: Chain; _client: RegistryClient; constructor (gqlUrl: string, restUrl = '', chainId: string = DEFAULT_CHAIN_ID) { @@ -103,11 +72,6 @@ export class Registry { this._client = new RegistryClient(gqlUrl, restUrl); this._chainID = chainId; - - this._chain = { - cosmosChainId: chainId, - chainId: this._parseEthChainId(chainId) - }; } /** @@ -468,35 +432,6 @@ export class Registry { ); } - /** - * https://evmos.dev/basics/chain_id.html - */ - _parseEthChainId (chainId: string) { - const [idWithChainNumber] = chainId.split('-'); - const [_, ethChainId] = idWithChainNumber.split('_'); - - return Number(ethChainId); - } - - /** - * Get sender used for creating message. - */ - async _getSender (account: Account) { - const accounts = await this.getAccounts([account.formattedCosmosAddress]); - if (!accounts.length) { - throw new Error('Account does not exist.'); - } - - const [{ number, sequence }] = accounts; - - return { - accountAddress: account.formattedCosmosAddress, - sequence: sequence, - accountNumber: number, - pubkey: account.encodedPubkey - }; - } - async getLaconicClient (account: Account) { return LaconicClient.connectWithSigner(this._endpoints.rest, account.wallet); } diff --git a/src/laconic-client.ts b/src/laconic-client.ts index eac0398..4362894 100644 --- a/src/laconic-client.ts +++ b/src/laconic-client.ts @@ -11,13 +11,12 @@ import { Comet38Client } from '@cosmjs/tendermint-rpc'; import { MsgCancelBondEncodeObject, MsgCreateBondEncodeObject, MsgRefillBondEncodeObject, MsgWithdrawBondEncodeObject, bondTypes, typeUrlMsgCancelBond, typeUrlMsgCreateBond, typeUrlMsgRefillBond, typeUrlMsgWithdrawBond } from './types/cerc/bond/message'; import { Coin } from './proto2/cosmos/base/v1beta1/coin'; -import { MsgAssociateBondEncodeObject, MsgDeleteNameEncodeObject, MsgDissociateBondEncodeObject, MsgDissociateRecordsEncodeObject, MsgReassociateRecordsEncodeObject, MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, MsgSetNameEncodeObject, MsgSetRecordEncodeObject, registryTypes, typeUrlMsgAssociateBond, typeUrlMsgDeleteName, typeUrlMsgDissociateBond, typeUrlMsgDissociateRecords, typeUrlMsgReassociateRecords, typeUrlMsgReserveAuthority, typeUrlMsgSetAuthorityBond, typeUrlMsgSetName, typeUrlMsgSetRecord } from './types/cerc/registry/message'; +import { MsgAssociateBondEncodeObject, MsgDeleteNameEncodeObject, MsgDissociateBondEncodeObject, MsgDissociateRecordsEncodeObject, MsgReassociateRecordsEncodeObject, MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, MsgSetNameEncodeObject, MsgSetRecordEncodeObject, registryTypes, typeUrlMsgAssociateBond, typeUrlMsgDeleteName, typeUrlMsgDissociateBond, typeUrlMsgDissociateRecords, typeUrlMsgReassociateRecords, typeUrlMsgReserveAuthority, typeUrlMsgSetAuthorityBond, typeUrlMsgSetName, typeUrlMsgSetRecord, NAMESERVICE_ERRORS } from './types/cerc/registry/message'; import { MsgCommitBidEncodeObject, MsgRevealBidEncodeObject, auctionTypes, typeUrlMsgCommitBid, typeUrlMsgRevealBid } from './types/cerc/auction/message'; import { MsgAssociateBondResponse, MsgDeleteNameResponse, MsgDissociateBondResponse, MsgDissociateRecordsResponse, MsgReassociateRecordsResponse, MsgReserveAuthorityResponse, MsgSetAuthorityBondResponse, MsgSetNameResponse, MsgSetRecordResponse, Payload } from './proto2/cerc/registry/v1/tx'; import { Record, Signature } from './proto2/cerc/registry/v1/registry'; import { Account } from './account'; import { Util } from './util'; -import { NAMESERVICE_ERRORS } from './messages/registry'; import { MsgCommitBidResponse, MsgRevealBidResponse } from './proto2/cerc/auction/v1/tx'; import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto2/cerc/bond/v1/tx'; import { bankTypes } from './types/cosmos/bank/message'; diff --git a/src/messages/auction.ts b/src/messages/auction.ts deleted file mode 100644 index b749e39..0000000 --- a/src/messages/auction.ts +++ /dev/null @@ -1,149 +0,0 @@ -import { - generateTypes -} from '@tharsis/eip712'; -import { - Chain, - Sender, - Fee -} from '@tharsis/transactions'; - -import * as auctionTx from '../proto/vulcanize/auction/v1beta1/tx'; -import { createTx } from './util'; - -const MSG_COMMIT_BID_TYPES = { - MsgValue: [ - { name: 'auction_id', type: 'string' }, - { name: 'commit_hash', type: 'string' }, - { name: 'signer', type: 'string' } - ] -}; - -export interface MessageMsgCommitBid { - auctionId: string, - commitHash: string, -} - -const MSG_REVEAL_BID_TYPES = { - MsgValue: [ - { name: 'auction_id', type: 'string' }, - { name: 'reveal', type: 'string' }, - { name: 'signer', type: 'string' } - ] -}; - -export interface MessageMsgRevealBid { - auctionId: string, - reveal: string, -} - -export function createTxMsgCommitBid ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgCommitBid -) { - const types = generateTypes(MSG_COMMIT_BID_TYPES); - - const msg = createMsgCommitBid( - params.auctionId, - params.commitHash, - sender.accountAddress - ); - - const msgCosmos = protoCreateMsgCommitBid( - params.auctionId, - params.commitHash, - sender.accountAddress - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -export function createTxMsgRevealBid ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgRevealBid -) { - const types = generateTypes(MSG_REVEAL_BID_TYPES); - - const msg = createMsgRevealBid( - params.auctionId, - params.reveal, - sender.accountAddress - ); - - const msgCosmos = protoCreateMsgRevealBid( - params.auctionId, - params.reveal, - sender.accountAddress - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -function createMsgCommitBid ( - auctionId: string, - commitHash: string, - signer: string -) { - return { - type: 'auction/MsgCommitBid', - value: { - auction_id: auctionId, - commit_hash: commitHash, - signer - } - }; -} - -const protoCreateMsgCommitBid = ( - auctionId: string, - commitHash: string, - signer: string -) => { - const commitBidMessage = new auctionTx.vulcanize.auction.v1beta1.MsgCommitBid({ - auction_id: auctionId, - commit_hash: commitHash, - signer - }); - - return { - message: commitBidMessage, - path: 'vulcanize.auction.v1beta1.MsgCommitBid' - }; -}; - -function createMsgRevealBid ( - auctionId: string, - reveal: string, - signer: string -) { - return { - type: 'auction/MsgRevealBid', - value: { - auction_id: auctionId, - reveal, - signer - } - }; -} - -const protoCreateMsgRevealBid = ( - auctionId: string, - reveal: string, - signer: string -) => { - const revealBidMessage = new auctionTx.vulcanize.auction.v1beta1.MsgRevealBid({ - auction_id: auctionId, - reveal, - signer - }); - - return { - message: revealBidMessage, - path: 'vulcanize.auction.v1beta1.MsgRevealBid' - }; -}; diff --git a/src/messages/bond.ts b/src/messages/bond.ts deleted file mode 100644 index 95b1e10..0000000 --- a/src/messages/bond.ts +++ /dev/null @@ -1,590 +0,0 @@ -import { - generateTypes -} from '@tharsis/eip712'; -import { - Chain, - Sender, - Fee -} from '@tharsis/transactions'; - -import * as bondTx from '../proto/vulcanize/bond/v1beta1/tx'; -import * as registryTx from '../proto/vulcanize/registry/v1beta1/tx'; -import * as coin from '../proto/cosmos/base/v1beta1/coin'; -import { createTx } from './util'; - -const MSG_CREATE_BOND_TYPES = { - MsgValue: [ - { name: 'signer', type: 'string' }, - { name: 'coins', type: 'TypeCoins[]' } - ], - TypeCoins: [ - { name: 'denom', type: 'string' }, - { name: 'amount', type: 'string' } - ] -}; - -const MSG_REFILL_BOND_TYPES = { - MsgValue: [ - { name: 'id', type: 'string' }, - { name: 'signer', type: 'string' }, - { name: 'coins', type: 'TypeCoins[]' } - ], - TypeCoins: [ - { name: 'denom', type: 'string' }, - { name: 'amount', type: 'string' } - ] -}; - -const MSG_WITHDRAW_BOND_TYPES = { - MsgValue: [ - { name: 'id', type: 'string' }, - { name: 'signer', type: 'string' }, - { name: 'coins', type: 'TypeCoins[]' } - ], - TypeCoins: [ - { name: 'denom', type: 'string' }, - { name: 'amount', type: 'string' } - ] -}; - -const MSG_CANCEL_BOND_TYPES = { - MsgValue: [ - { name: 'id', type: 'string' }, - { name: 'signer', type: 'string' } - ] -}; - -const MSG_ASSOCIATE_BOND_TYPES = { - MsgValue: [ - { name: 'record_id', type: 'string' }, - { name: 'bond_id', type: 'string' }, - { name: 'signer', type: 'string' } - ] -}; - -const MSG_DISSOCIATE_BOND_TYPES = { - MsgValue: [ - { name: 'record_id', type: 'string' }, - { name: 'signer', type: 'string' } - ] -}; - -const MSG_DISSOCIATE_RECORDS_TYPES = { - MsgValue: [ - { name: 'bond_id', type: 'string' }, - { name: 'signer', type: 'string' } - ] -}; - -const MSG_REASSOCIATE_RECORDS_TYPES = { - MsgValue: [ - { name: 'new_bond_id', type: 'string' }, - { name: 'old_bond_id', type: 'string' }, - { name: 'signer', type: 'string' } - ] -}; - -export interface MessageMsgCreateBond { - amount: string - denom: string -} - -export interface MessageMsgRefillBond { - id: string, - amount: string - denom: string -} - -export interface MessageMsgWithdrawBond { - id: string - amount: string - denom: string -} - -export interface MessageMsgCancelBond { - id: string -} - -export interface MessageMsgAssociateBond { - bondId: string, - recordId: string -} - -export interface MessageMsgDissociateBond { - recordId: string -} - -export interface MessageMsgDissociateRecords { - bondId: string -} - -export interface MessageMsgReAssociateRecords { - newBondId: string - oldBondId: string -} - -export function createTxMsgCreateBond ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgCreateBond -) { - const types = generateTypes(MSG_CREATE_BOND_TYPES); - - const msg = createMsgCreateBond( - sender.accountAddress, - params.amount, - params.denom - ); - - const msgCosmos = protoCreateMsgCreateBond( - sender.accountAddress, - params.amount, - params.denom - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -export function createTxMsgRefillBond ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgRefillBond -) { - const types = generateTypes(MSG_REFILL_BOND_TYPES); - - const msg = createMsgRefillBond( - params.id, - sender.accountAddress, - params.amount, - params.denom - ); - - const msgCosmos = protoCreateMsgRefillBond( - params.id, - sender.accountAddress, - params.amount, - params.denom - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -export function createTxMsgWithdrawBond ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgWithdrawBond -) { - const types = generateTypes(MSG_WITHDRAW_BOND_TYPES); - - const msg = createMsgWithdrawBond( - params.id, - sender.accountAddress, - params.amount, - params.denom - ); - - const msgCosmos = protoCreateMsgWithdrawBond( - params.id, - sender.accountAddress, - params.amount, - params.denom - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -export function createTxMsgCancelBond ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgCancelBond -) { - const types = generateTypes(MSG_CANCEL_BOND_TYPES); - - const msg = createMsgCancelBond( - params.id, - sender.accountAddress - ); - - const msgCosmos = protoCreateMsgCancelBond( - params.id, - sender.accountAddress - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -export function createTxMsgAssociateBond ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgAssociateBond -) { - const types = generateTypes(MSG_ASSOCIATE_BOND_TYPES); - - const msg = createMsgAssociateBond( - params.recordId, - params.bondId, - sender.accountAddress - ); - - const msgCosmos = protoCreateMsgAssociateBond( - params.recordId, - params.bondId, - sender.accountAddress - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -export function createTxMsgDissociateBond ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgDissociateBond -) { - const types = generateTypes(MSG_DISSOCIATE_BOND_TYPES); - - const msg = createMsgDissociateBond( - params.recordId, - sender.accountAddress - ); - - const msgCosmos = protoCreateMsgDissociateBond( - params.recordId, - sender.accountAddress - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -export function createTxMsgDissociateRecords ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgDissociateRecords -) { - const types = generateTypes(MSG_DISSOCIATE_RECORDS_TYPES); - - const msg = createMsgDissociateRecords( - params.bondId, - sender.accountAddress - ); - - const msgCosmos = protoCreateMsgDissociateRecords( - params.bondId, - sender.accountAddress - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -export function createTxMsgReAssociateRecords ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgReAssociateRecords -) { - const types = generateTypes(MSG_REASSOCIATE_RECORDS_TYPES); - - const msg = createMsgReAssociateRecords( - params.newBondId, - params.oldBondId, - sender.accountAddress - ); - - const msgCosmos = protoCreateMsgReAssociateRecords( - params.newBondId, - params.oldBondId, - sender.accountAddress - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -function createMsgCreateBond ( - signer: string, - amount: string, - denom: string -) { - return { - type: 'bond/MsgCreateBond', - value: { - coins: [ - { - amount, - denom - } - ], - signer - } - }; -} - -const protoCreateMsgCreateBond = ( - signer: string, - amount: string, - denom: string -) => { - const value = new coin.cosmos.base.v1beta1.Coin({ - denom, - amount - }); - - const createBondMessage = new bondTx.vulcanize.bond.v1beta1.MsgCreateBond({ - signer, - coins: [value] - }); - - return { - message: createBondMessage, - path: 'vulcanize.bond.v1beta1.MsgCreateBond' - }; -}; - -function createMsgRefillBond ( - id: string, - signer: string, - amount: string, - denom: string -) { - return { - type: 'bond/MsgRefillBond', - value: { - coins: [ - { - amount, - denom - } - ], - id, - signer - } - }; -} - -const protoCreateMsgRefillBond = ( - id: string, - signer: string, - amount: string, - denom: string -) => { - const value = new coin.cosmos.base.v1beta1.Coin({ - denom, - amount - }); - - const refillBondMessage = new bondTx.vulcanize.bond.v1beta1.MsgRefillBond({ - id, - signer, - coins: [value] - }); - - return { - message: refillBondMessage, - path: 'vulcanize.bond.v1beta1.MsgRefillBond' - }; -}; - -function createMsgWithdrawBond ( - id: string, - signer: string, - amount: string, - denom: string -) { - return { - type: 'bond/MsgWithdrawBond', - value: { - id, - coins: [ - { - amount, - denom - } - ], - signer - } - }; -} - -const protoCreateMsgWithdrawBond = ( - id: string, - signer: string, - amount: string, - denom: string -) => { - const value = new coin.cosmos.base.v1beta1.Coin({ - denom, - amount - }); - - const withdrawBondMessage = new bondTx.vulcanize.bond.v1beta1.MsgWithdrawBond({ - id, - signer, - coins: [value] - }); - - return { - message: withdrawBondMessage, - path: 'vulcanize.bond.v1beta1.MsgWithdrawBond' - }; -}; - -function createMsgCancelBond ( - id: string, - signer: string -) { - return { - type: 'bond/MsgCancelBond', - value: { - id, - signer - } - }; -} - -const protoCreateMsgCancelBond = ( - id: string, - signer: string -) => { - const cancelBondMessage = new bondTx.vulcanize.bond.v1beta1.MsgCancelBond({ - id, - signer - }); - - return { - message: cancelBondMessage, - path: 'vulcanize.bond.v1beta1.MsgCancelBond' - }; -}; - -function createMsgAssociateBond ( - recordId: string, - bondId: string, - signer: string -) { - return { - type: 'registry/AssociateBond', - value: { - record_id: recordId, - bond_id: bondId, - signer - } - }; -} - -const protoCreateMsgAssociateBond = ( - recordId: string, - bondId: string, - signer: string -) => { - const associateBondMessage = new registryTx.vulcanize.registry.v1beta1.MsgAssociateBond({ - record_id: recordId, - bond_id: bondId, - signer - }); - - return { - message: associateBondMessage, - path: 'vulcanize.registry.v1beta1.MsgAssociateBond' - }; -}; - -function createMsgDissociateBond ( - recordId: string, - signer: string -) { - return { - type: 'registry/DissociateBond', - value: { - record_id: recordId, - signer - } - }; -} - -const protoCreateMsgDissociateBond = ( - recordId: string, - signer: string -) => { - const dissociateBondMessage = new registryTx.vulcanize.registry.v1beta1.MsgDissociateBond({ - record_id: recordId, - signer - }); - - return { - message: dissociateBondMessage, - path: 'vulcanize.registry.v1beta1.MsgDissociateBond' - }; -}; - -function createMsgDissociateRecords ( - bondId: string, - signer: string -) { - return { - type: 'registry/DissociateRecords', - value: { - bond_id: bondId, - signer - } - }; -} - -const protoCreateMsgDissociateRecords = ( - bondId: string, - signer: string -) => { - const dissociateRecordsMessage = new registryTx.vulcanize.registry.v1beta1.MsgDissociateRecords({ - bond_id: bondId, - signer - }); - - return { - message: dissociateRecordsMessage, - path: 'vulcanize.registry.v1beta1.MsgDissociateRecords' - }; -}; - -function createMsgReAssociateRecords ( - newBondId: string, - oldBondId: string, - signer: string -) { - return { - type: 'registry/ReassociateRecords', - value: { - new_bond_id: newBondId, - old_bond_id: oldBondId, - signer - } - }; -} - -const protoCreateMsgReAssociateRecords = ( - newBondId: string, - oldBondId: string, - signer: string -) => { - const reAssociateRecordsMessage = new registryTx.vulcanize.registry.v1beta1.MsgReAssociateRecords({ - new_bond_id: newBondId, - old_bond_id: oldBondId, - signer - }); - - return { - message: reAssociateRecordsMessage, - path: 'vulcanize.registry.v1beta1.MsgReAssociateRecords' - }; -}; diff --git a/src/messages/registry.ts b/src/messages/registry.ts deleted file mode 100644 index 2e4f258..0000000 --- a/src/messages/registry.ts +++ /dev/null @@ -1,323 +0,0 @@ -import { - generateTypes -} from '@tharsis/eip712'; -import { - Chain, - Sender, - Fee -} from '@tharsis/transactions'; - -import * as registryTx from '../proto/vulcanize/registry/v1beta1/tx'; -import { createTx } from './util'; - -const MSG_RESERVE_AUTHORITY_TYPES = { - MsgValue: [ - { name: 'name', type: 'string' }, - { name: 'signer', type: 'string' }, - { name: 'owner', type: 'string' } - ] -}; - -const MSG_SET_NAME_TYPES = { - MsgValue: [ - { name: 'crn', type: 'string' }, - { name: 'cid', type: 'string' }, - { name: 'signer', type: 'string' } - ] -}; - -const MSG_SET_RECORD_TYPES = { - MsgValue: [ - { name: 'bond_id', type: 'string' }, - { name: 'signer', type: 'string' }, - { name: 'payload', type: 'TypePayload' } - ], - TypePayload: [ - { name: 'record', type: 'TypePayloadRecord' }, - { name: 'signatures', type: 'TypePayloadSignatures[]' } - ], - TypePayloadRecord: [ - { name: 'id', type: 'string' }, - { name: 'bond_id', type: 'string' }, - { name: 'create_time', type: 'string' }, - { name: 'expiry_time', type: 'string' }, - { name: 'deleted', type: 'bool' }, - { name: 'attributes', type: 'bytes' } - ], - TypePayloadSignatures: [ - { name: 'sig', type: 'string' }, - { name: 'pub_key', type: 'string' } - ] -}; - -const MSG_SET_AUTHORITY_BOND_TYPES = { - MsgValue: [ - { name: 'name', type: 'string' }, - { name: 'bond_id', type: 'string' }, - { name: 'signer', type: 'string' } - ] -}; - -const MSG_DELETE_NAME_TYPES = { - MsgValue: [ - { name: 'crn', type: 'string' }, - { name: 'signer', type: 'string' } - ] -}; - -export const parseMsgSetRecordResponse = (data: string) => { - const responseBytes = Buffer.from(data, 'hex'); - - // TODO: Decode response using protobuf. - // const msgSetRecordResponse = nameserviceTx.vulcanize.nameservice.v1beta1.MsgSetRecordResponse.deserialize(responseBytes); - // return msgSetRecordResponse.toObject(); - - // Workaround as proto based decoding is not working. - const [_, id] = responseBytes.toString().split(';'); - - return { id }; -}; - -export const NAMESERVICE_ERRORS = [ - 'Name already reserved.', - 'Authority bond not found.', - 'Name authority not found.', - 'Access denied.' -]; - -export interface MessageMsgReserveAuthority { - name: string - owner: string -} - -export interface MessageMsgSetName { - lrn: string - cid: string -} - -export interface MessageMsgSetAuthorityBond { - name: string - bondId: string -} - -export interface MessageMsgDeleteName { - lrn: string -} - -export function createTxMsgReserveAuthority ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgReserveAuthority -) { - const types = generateTypes(MSG_RESERVE_AUTHORITY_TYPES); - - const msg = createMsgReserveAuthority( - params.name, - sender.accountAddress, - params.owner - ); - - const msgCosmos = protoCreateMsgReserveAuthority( - params.name, - sender.accountAddress, - params.owner - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -export function createTxMsgSetName ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgSetName -) { - const types = generateTypes(MSG_SET_NAME_TYPES); - - const msg = createMsgSetName( - params.lrn, - params.cid, - sender.accountAddress - ); - - const msgCosmos = protoCreateMsgSetName( - params.lrn, - params.cid, - sender.accountAddress - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -export function createTxMsgSetAuthorityBond ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgSetAuthorityBond -) { - const types = generateTypes(MSG_SET_AUTHORITY_BOND_TYPES); - - const msg = createMsgSetAuthorityBond( - params.name, - params.bondId, - sender.accountAddress - ); - - const msgCosmos = protoCreateMsgSetAuthorityBond( - params.name, - params.bondId, - sender.accountAddress - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -export function createTxMsgDeleteName ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - params: MessageMsgDeleteName -) { - const types = generateTypes(MSG_DELETE_NAME_TYPES); - - const msg = createMsgDeleteName( - params.lrn, - sender.accountAddress - ); - - const msgCosmos = protoCreateMsgDeleteName( - params.lrn, - sender.accountAddress - ); - - return createTx(chain, sender, fee, memo, types, msg, msgCosmos); -} - -function createMsgReserveAuthority ( - name: string, - signer: string, - owner: string -) { - return { - type: 'registry/ReserveAuthority', - value: { - name, - signer, - owner - } - }; -} - -const protoCreateMsgReserveAuthority = ( - name: string, - signer: string, - owner: string -) => { - const reserveAuthorityMessage = new registryTx.vulcanize.registry.v1beta1.MsgReserveAuthority({ - name, - signer, - owner - }); - - return { - message: reserveAuthorityMessage, - path: 'vulcanize.registry.v1beta1.MsgReserveAuthority' - }; -}; - -function createMsgSetName ( - crn: string, - cid: string, - signer: string -) { - return { - type: 'registry/SetName', - value: { - crn, - cid, - signer - } - }; -} - -const protoCreateMsgSetName = ( - crn: string, - cid: string, - signer: string -) => { - const setNameMessage = new registryTx.vulcanize.registry.v1beta1.MsgSetName({ - crn, - cid, - signer - }); - - return { - message: setNameMessage, - path: 'vulcanize.registry.v1beta1.MsgSetName' - }; -}; - -function createMsgSetAuthorityBond ( - name: string, - bondId: string, - signer: string -) { - return { - type: 'registry/SetAuthorityBond', - value: { - name, - bond_id: bondId, - signer - } - }; -} - -const protoCreateMsgSetAuthorityBond = ( - name: string, - bondId: string, - signer: string -) => { - const setAuthorityBondMessage = new registryTx.vulcanize.registry.v1beta1.MsgSetAuthorityBond({ - name, - bond_id: bondId, - signer - }); - - return { - message: setAuthorityBondMessage, - path: 'vulcanize.registry.v1beta1.MsgSetAuthorityBond' - }; -}; - -function createMsgDeleteName ( - crn: string, - signer: string -) { - return { - type: 'registry/DeleteAuthority', - value: { - crn, - signer - } - }; -} - -const protoCreateMsgDeleteName = ( - crn: string, - signer: string -) => { - const deleteNameAutorityMessage = new registryTx.vulcanize.registry.v1beta1.MsgDeleteNameAuthority({ - crn, - signer - }); - - return { - message: deleteNameAutorityMessage, - path: 'vulcanize.registry.v1beta1.MsgDeleteNameAuthority' - }; -}; diff --git a/src/messages/util.ts b/src/messages/util.ts deleted file mode 100644 index c85a04f..0000000 --- a/src/messages/util.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { Message } from 'google-protobuf'; -import { - createEIP712, - generateFee, - generateMessage, - generateTypes -} from '@tharsis/eip712'; -import { - Chain, - Sender, - Fee -} from '@tharsis/transactions'; -import { createTransaction } from '@tharsis/proto'; - -interface Msg { - type: string - value: any -} - -interface MsgCosmos { - message: Message - path: string -} - -interface Types { - [key: string]: Array<{ - name: string - type: string - }> -} - -export const createTx = ( - chain: Chain, - sender: Sender, - fee: Fee, - memo: string, - messageTypes: Types, - msg: Msg, - msgCosmos: MsgCosmos -) => { - // EIP712 - const feeObject = generateFee( - fee.amount, - fee.denom, - fee.gas, - sender.accountAddress - ); - const types = generateTypes(messageTypes); - - const messages = generateMessage( - sender.accountNumber.toString(), - sender.sequence.toString(), - chain.cosmosChainId, - memo, - feeObject, - msg - ); - const eipToSign = createEIP712(types, chain.chainId, messages); - - // Cosmos - const tx = createTransaction( - msgCosmos, - memo, - fee.amount, - fee.denom, - parseInt(fee.gas, 10), - 'ethsecp256', - sender.pubkey, - sender.sequence, - sender.accountNumber, - chain.cosmosChainId - ); - - return { - signDirect: tx.signDirect, - legacyAmino: tx.legacyAmino, - eipToSign - }; -}; diff --git a/src/registry-client.ts b/src/registry-client.ts index 9372926..ac1f48a 100644 --- a/src/registry-client.ts +++ b/src/registry-client.ts @@ -1,8 +1,6 @@ import assert from 'assert'; -import axios from 'axios'; import graphqlClient from 'graphql.js'; import { get, set } from 'lodash'; -import { generateEndpointAccount, generateEndpointBroadcast } from '@tharsis/provider'; import { Util } from './util'; @@ -419,19 +417,4 @@ export class RegistryClient { return RegistryClient.getResult(this._graph(query)(variables), 'queryBonds'); } - - /** - * Submit transaction. - */ - async submit (tx: string) { - assert(tx); - - // Broadcast transaction. - const { data } = await axios.post( - `${this._restEndpoint}${generateEndpointBroadcast()}`, - tx - ); - - return data; - } } diff --git a/src/schema/record.json b/src/schema/record.json deleted file mode 100644 index 2761e2d..0000000 --- a/src/schema/record.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "id": "/Record", - "type": "object" -} diff --git a/src/testing/helper.ts b/src/testing/helper.ts index 6a7579e..8ca88bf 100644 --- a/src/testing/helper.ts +++ b/src/testing/helper.ts @@ -1,9 +1,8 @@ import assert from 'assert'; import yaml from 'node-yaml'; import semver from 'semver'; -import { Fee } from '@tharsis/transactions'; -import { DEFAULT_CHAIN_ID, Registry } from '../index'; +import { DEFAULT_CHAIN_ID } from '../index'; export const ensureUpdatedConfig = async (path: string) => { const conf = await yaml.read(path); diff --git a/src/txbuilder.ts b/src/txbuilder.ts deleted file mode 100644 index c7301a0..0000000 --- a/src/txbuilder.ts +++ /dev/null @@ -1,25 +0,0 @@ -import assert from 'assert'; -import { - createTxRawEIP712, - signatureToWeb3Extension, - Chain, - Sender -} from '@tharsis/transactions'; - -import { Account } from './account'; - -/** - * Generate a cosmos-sdk transaction. - */ -export const createTransaction = (message: any, account: Account, sender: Sender, chain: Chain) => { - assert(message); - assert(account); - - // Sign transaction. - const signature = account.sign(message); - - let extension = signatureToWeb3Extension(chain, sender, signature); - - // Create the txRaw. - return createTxRawEIP712(message.legacyAmino.body, message.legacyAmino.authInfo, extension); -}; diff --git a/src/types/cerc/auction/message.ts b/src/types/cerc/auction/message.ts index 87c4abe..80f3732 100644 --- a/src/types/cerc/auction/message.ts +++ b/src/types/cerc/auction/message.ts @@ -23,3 +23,13 @@ export interface MsgRevealBidEncodeObject extends EncodeObject { readonly typeUrl: '/cerc.auction.v1.MsgRevealBid'; readonly value: Partial; } + +export interface MessageMsgCommitBid { + auctionId: string, + commitHash: string, +} + +export interface MessageMsgRevealBid { + auctionId: string, + reveal: string, +} diff --git a/src/types/cerc/bond/message.ts b/src/types/cerc/bond/message.ts index 70c6162..08d4439 100644 --- a/src/types/cerc/bond/message.ts +++ b/src/types/cerc/bond/message.ts @@ -50,3 +50,42 @@ export interface MsgCancelBondEncodeObject extends EncodeObject { readonly typeUrl: '/cerc.bond.v1.MsgCancelBond'; readonly value: Partial; } + +export interface MessageMsgCreateBond { + amount: string + denom: string +} + +export interface MessageMsgRefillBond { + id: string, + amount: string + denom: string +} + +export interface MessageMsgWithdrawBond { + id: string + amount: string + denom: string +} + +export interface MessageMsgCancelBond { + id: string +} + +export interface MessageMsgAssociateBond { + bondId: string, + recordId: string +} + +export interface MessageMsgDissociateBond { + recordId: string +} + +export interface MessageMsgDissociateRecords { + bondId: string +} + +export interface MessageMsgReAssociateRecords { + newBondId: string + oldBondId: string +} diff --git a/src/types/cerc/registry/message.ts b/src/types/cerc/registry/message.ts index e07376f..b048720 100644 --- a/src/types/cerc/registry/message.ts +++ b/src/types/cerc/registry/message.ts @@ -86,3 +86,29 @@ export interface MsgReassociateRecordsEncodeObject extends EncodeObject { readonly typeUrl: '/cerc.registry.v1.MsgReassociateRecords'; readonly value: Partial; } + +export const NAMESERVICE_ERRORS = [ + 'Name already reserved.', + 'Authority bond not found.', + 'Name authority not found.', + 'Access denied.' +]; + +export interface MessageMsgReserveAuthority { + name: string + owner: string +} + +export interface MessageMsgSetName { + lrn: string + cid: string +} + +export interface MessageMsgSetAuthorityBond { + name: string + bondId: string +} + +export interface MessageMsgDeleteName { + lrn: string +}