Setup eslint and husky pre-commit (#3)

* Set up eslint and husky

* Fix eslint errors

---------

Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
Nabarun Gogoi 2024-03-07 09:47:05 +05:30 committed by GitHub
parent f2401e6953
commit de0ac597a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 2009 additions and 661 deletions

5
.eslintignore Normal file
View File

@ -0,0 +1,5 @@
# Don't lint node_modules.
node_modules
# Don't lint build output.
dist

29
.eslintrc.json Normal file
View File

@ -0,0 +1,29 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"semistandard",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
// TODO: Remove after resolution
"indent": ["error", 2, { "SwitchCase": 1 }],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"prefer-const": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/ban-ts-comment": "off",
"camelcase": "off",
"@typescript-eslint/ban-types": "off"
}
}

1
.husky/pre-commit Normal file
View File

@ -0,0 +1 @@
yarn lint

View File

@ -2,5 +2,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
setupFiles: ["dotenv/config"]
setupFiles: ['dotenv/config']
};

View File

@ -11,8 +11,18 @@
"@types/lodash": "^4.14.181",
"@types/semver": "^7.3.9",
"@types/tiny-secp256k1": "1.0.0",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"dotenv": "^16.0.0",
"eslint": "^8.35.0",
"eslint-config-semistandard": "^15.0.1",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"google-protobuf": "^3.21.0",
"husky": "^9.0.11",
"jest": "29.0.0",
"ts-jest": "^29.0.2",
"ts-proto": "1.121.6",
@ -55,6 +65,8 @@
"test": "jest --runInBand --verbose --testPathPattern=src",
"test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/auction.test.ts",
"test:nameservice-expiry": "TEST_NAMESERVICE_EXPIRY=1 jest --runInBand --verbose src/nameservice-expiry.test.ts",
"build": "tsc"
"build": "tsc",
"lint": "eslint .",
"prepare": "husky"
}
}

View File

@ -7,17 +7,17 @@ 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 { Ripemd160 } from '@cosmjs/crypto';
import { fromHex, toHex } from '@cosmjs/encoding';
import { ethToEthermint } from "@tharsis/address-converter"
import { ethToEthermint } from '@tharsis/address-converter';
import { encodeSecp256k1Pubkey } from '@cosmjs/amino';
import { DirectSecp256k1Wallet } from "@cosmjs/proto-signing";
import { DirectSecp256k1Wallet } from '@cosmjs/proto-signing';
import { Payload, Signature } from './types';
const AMINO_PREFIX = 'EB5AE98721';
const HDPATH = "m/44'/60'/0'/0";
const ACCOUNT_PREFIX = "laconic";
const ACCOUNT_PREFIX = 'laconic';
const bip32 = BIP32Factory(ecc);
@ -33,15 +33,15 @@ interface TypedMessageDomain {
* Registry account.
*/
export class Account {
_privateKey: Buffer
_publicKey!: Uint8Array
_encodedPubkey!: string
_formattedCosmosAddress!: string
_registryPublicKey!: string
_registryAddress!: string
_ethAddress!: string
_wallet!: DirectSecp256k1Wallet
_address!: string
_privateKey: Buffer;
_publicKey!: Uint8Array;
_encodedPubkey!: string;
_formattedCosmosAddress!: string;
_registryPublicKey!: string;
_registryAddress!: string;
_ethAddress!: string;
_wallet!: DirectSecp256k1Wallet;
_address!: string;
/**
* Generate bip39 mnemonic.
@ -107,14 +107,14 @@ export class Account {
ACCOUNT_PREFIX
);
this._address = (await this._wallet.getAccounts())[0].address
this._address = (await this._wallet.getAccounts())[0].address;
// Generate public key.
this._publicKey = secp256k1.publicKeyCreate(this._privateKey)
this._encodedPubkey = encodeSecp256k1Pubkey(this._publicKey).value
this._publicKey = secp256k1.publicKeyCreate(this._privateKey);
this._encodedPubkey = encodeSecp256k1Pubkey(this._publicKey).value;
// 2. Generate eth address.
this._ethAddress = utils.computeAddress(this._publicKey)
this._ethAddress = utils.computeAddress(this._publicKey);
// 3. Generate cosmos-sdk formatted address.
this._formattedCosmosAddress = ethToEthermint(this._ethAddress);
@ -169,7 +169,7 @@ export class Account {
const messageToSign = record.getMessageToSign();
const sig = await this.signRecord(messageToSign);
assert(this.registryPublicKey)
assert(this.registryPublicKey);
const signature = new Signature(this.registryPublicKey, sig.toString('base64'));
payload.addSignature(signature);
@ -192,7 +192,7 @@ export class Account {
},
privateKey: this._privateKey,
version: SignTypedDataVersion.V4
})
});
return signature;
}

View File

@ -119,7 +119,6 @@ if (!process.env.TEST_AUCTIONS_ENABLED) {
TEST_AUCTION_ENABLED=true ./init.sh
Run tests:
yarn test:auctions

View File

@ -2,13 +2,13 @@ import path from 'path';
import { Registry } from './index';
import { ensureUpdatedConfig, getConfig, getLaconic2Config } from './testing/helper';
import { DENOM } from './constants'
import { DENOM } from './constants';
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
const BOND_AMOUNT = "10000";
const BOND_AMOUNT = '10000';
const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
const { fee: laconic2Fee } = getLaconic2Config()
const { fee: laconic2Fee } = getLaconic2Config();
jest.setTimeout(90 * 1000);
@ -32,7 +32,7 @@ const bondTests = () => {
});
describe('With bond created', () => {
let bond1: any
let bond1: any;
beforeAll(async () => {
let bondId1 = await registry.getNextBondId(privateKey);
@ -67,7 +67,7 @@ const bondTests = () => {
});
test('Refill bond.', async () => {
const refillAmount = "500";
const refillAmount = '500';
const total = (parseInt(BOND_AMOUNT) + parseInt(refillAmount)).toString();
await registry.refillBond({ id: bond1.id, denom: DENOM, amount: refillAmount }, privateKey, laconic2Fee);
const [bond] = await registry.getBondsByIds([bond1.id]);
@ -78,7 +78,7 @@ const bondTests = () => {
});
test('Withdraw bond.', async () => {
await registry.withdrawBond({ id: bond1.id, denom: DENOM, amount: "500" }, privateKey, laconic2Fee);
await registry.withdrawBond({ id: bond1.id, denom: DENOM, amount: '500' }, privateKey, laconic2Fee);
const [bond] = await registry.getBondsByIds([bond1.id]);
expect(bond).toBeDefined();
expect(bond.id).toBe(bond1.id);
@ -89,11 +89,10 @@ const bondTests = () => {
test('Cancel bond.', async () => {
await registry.cancelBond({ id: bond1.id }, privateKey, laconic2Fee);
const [bond] = await registry.getBondsByIds([bond1.id]);
expect(bond.id).toBe("");
expect(bond.owner).toBe("");
expect(bond.id).toBe('');
expect(bond.owner).toBe('');
expect(bond.balance).toHaveLength(0);
});
});
test('Associate/Dissociate bond.', async () => {

View File

@ -1 +1 @@
export const DENOM = "photon";
export const DENOM = 'photon';

View File

@ -11,23 +11,22 @@ const registryTests = () => {
beforeAll(async () => {
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
});
test('Get account info.', async () => {
const account = new Account(Buffer.from(privateKey, 'hex'));
const accounts = await registry.getAccounts([account.formattedCosmosAddress]);
expect(accounts).toHaveLength(1)
expect(accounts).toHaveLength(1);
const [accountObj] = accounts;
expect(accountObj.address).toBe(account.formattedCosmosAddress);
expect(accountObj.pubKey).toBe(account.encodedPubkey);
expect(accountObj.number).toBe('0');
expect(accountObj.sequence).toBeDefined();
expect(accountObj.balance).toHaveLength(1);
const [{ type, quantity }] = accountObj.balance
const [{ type, quantity }] = accountObj.balance;
expect(type).toBe('aphoton');
expect(quantity).toBeDefined();
})
});
test('Get account balance.', async () => {
const mnenonic1 = Account.generateMnemonic();
@ -37,10 +36,10 @@ const registryTests = () => {
const [accountObj] = await registry.getAccounts([otherAccount.formattedCosmosAddress]);
expect(accountObj).toBeDefined();
expect(accountObj.address).toBe(otherAccount.formattedCosmosAddress);
const [{ type, quantity }] = accountObj.balance
const [{ type, quantity }] = accountObj.balance;
expect(type).toBe('aphoton');
expect(quantity).toBe('100000000');
})
}
});
};
describe('Registry', registryTests);

View File

@ -6,12 +6,12 @@ import {
Fee,
createMessageSend,
MessageSendParams
} from '@tharsis/transactions'
} from '@tharsis/transactions';
import { DeliverTxResponse, GasPrice, StdFee } from '@cosmjs/stargate';
import { RegistryClient } from "./registry-client";
import { Account } from "./account";
import { createTransaction } from "./txbuilder";
import { RegistryClient } from './registry-client';
import { Account } from './account';
import { createTransaction } from './txbuilder';
import { Payload, Record } from './types';
import { Util } from './util';
import {
@ -31,7 +31,7 @@ import {
MessageMsgReAssociateRecords,
MessageMsgRefillBond,
MessageMsgWithdrawBond
} from "./messages/bond";
} from './messages/bond';
import {
createTxMsgDeleteName,
createTxMsgReserveAuthority,
@ -64,7 +64,7 @@ export const parseTxResponse = (result: any, parseResponse?: (data: string) => a
const { txhash: hash, height, ...txResponse } = result;
if (parseResponse) {
txResponse.data = parseResponse(txResponse.data)
txResponse.data = parseResponse(txResponse.data);
}
txResponse.events.forEach((event:any) => {
@ -106,25 +106,24 @@ 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
_endpoints: {[key: string]: string};
_chainID: string;
_chain: Chain;
_client: RegistryClient;
static processWriteError (error: string) {
// error string a stacktrace containing the message.
// https://gist.github.com/nikugogoi/de55d390574ded3466abad8bffd81952#file-txresponse-js-L7
const errorMessage = NAMESERVICE_ERRORS.find(message => error.includes(message))
const errorMessage = NAMESERVICE_ERRORS.find(message => error.includes(message));
if (!errorMessage) {
console.error(error)
console.error(error);
}
return errorMessage || DEFAULT_WRITE_ERROR;
}
constructor(gqlUrl: string, restUrl: string = "", chainId: string = DEFAULT_CHAIN_ID) {
constructor (gqlUrl: string, restUrl = '', chainId: string = DEFAULT_CHAIN_ID) {
this._endpoints = {
rest: restUrl,
gql: gqlUrl
@ -205,7 +204,7 @@ export class Registry {
const account = new Account(Buffer.from(privateKey, 'hex'));
const sender = await this._getSender(account);
const msg = createMessageSend(this._chain, sender, fee, '', params)
const msg = createMessageSend(this._chain, sender, fee, '', params);
result = await this._submitTx(msg, privateKey, sender);
return parseTxResponse(result);
@ -217,7 +216,7 @@ export class Registry {
async getNextBondId (privateKey: string) {
let result;
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init()
await account.init();
const accounts = await this.getAccounts([account.address]);
if (!accounts.length) {
throw new Error('Account does not exist.');
@ -248,9 +247,9 @@ export class Registry {
* Create bond.
*/
async createBond ({ denom, amount }: MessageMsgCreateBond, privateKey: string, fee: StdFee): Promise<MsgCreateBondResponse> {
const account = new Account(Buffer.from(privateKey, 'hex'))
await account.init()
const laconicClient = await this.getLaconicClient(account)
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
const response: DeliverTxResponse = await laconicClient.createBond(
account.address,
@ -259,16 +258,16 @@ export class Registry {
fee
);
return laconicClient.registry.decode(response.msgResponses[0])
return laconicClient.registry.decode(response.msgResponses[0]);
}
/**
* Refill bond.
*/
async refillBond ({ denom, amount, id }: MessageMsgRefillBond, privateKey: string, fee: StdFee): Promise<MsgRefillBondResponse> {
const account = new Account(Buffer.from(privateKey, 'hex'))
await account.init()
const laconicClient = await this.getLaconicClient(account)
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
const response: DeliverTxResponse = await laconicClient.refillBond(
account.address,
@ -278,16 +277,16 @@ export class Registry {
fee
);
return laconicClient.registry.decode(response.msgResponses[0])
return laconicClient.registry.decode(response.msgResponses[0]);
}
/**
* Withdraw (from) bond.
*/
async withdrawBond ({ denom, amount, id }: MessageMsgWithdrawBond, privateKey: string, fee: StdFee): Promise<MsgWithdrawBondResponse> {
const account = new Account(Buffer.from(privateKey, 'hex'))
await account.init()
const laconicClient = await this.getLaconicClient(account)
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
const response: DeliverTxResponse = await laconicClient.withdrawBond(
account.address,
@ -297,16 +296,16 @@ export class Registry {
fee
);
return laconicClient.registry.decode(response.msgResponses[0])
return laconicClient.registry.decode(response.msgResponses[0]);
}
/**
* Cancel bond.
*/
async cancelBond ({ id }: MessageMsgCancelBond, privateKey: string, fee: StdFee): Promise<MsgCancelBondResponse> {
const account = new Account(Buffer.from(privateKey, 'hex'))
await account.init()
const laconicClient = await this.getLaconicClient(account)
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
const response: DeliverTxResponse = await laconicClient.cancelBond(
account.address,
@ -314,7 +313,7 @@ export class Registry {
fee
);
return laconicClient.registry.decode(response.msgResponses[0])
return laconicClient.registry.decode(response.msgResponses[0]);
}
/**
@ -325,7 +324,7 @@ export class Registry {
const account = new Account(Buffer.from(privateKey, 'hex'));
const sender = await this._getSender(account);
const msg = createTxMsgAssociateBond(this._chain, sender, fee, '', params)
const msg = createTxMsgAssociateBond(this._chain, sender, fee, '', params);
result = await this._submitTx(msg, privateKey, sender);
return parseTxResponse(result);
@ -339,7 +338,7 @@ export class Registry {
const account = new Account(Buffer.from(privateKey, 'hex'));
const sender = await this._getSender(account);
const msg = createTxMsgDissociateBond(this._chain, sender, fee, '', params)
const msg = createTxMsgDissociateBond(this._chain, sender, fee, '', params);
result = await this._submitTx(msg, privateKey, sender);
return parseTxResponse(result);
@ -353,7 +352,7 @@ export class Registry {
const account = new Account(Buffer.from(privateKey, 'hex'));
const sender = await this._getSender(account);
const msg = createTxMsgDissociateRecords(this._chain, sender, fee, '', params)
const msg = createTxMsgDissociateRecords(this._chain, sender, fee, '', params);
result = await this._submitTx(msg, privateKey, sender);
return parseTxResponse(result);
@ -367,7 +366,7 @@ export class Registry {
const account = new Account(Buffer.from(privateKey, 'hex'));
const sender = await this._getSender(account);
const msg = createTxMsgReAssociateRecords(this._chain, sender, fee, '', params)
const msg = createTxMsgReAssociateRecords(this._chain, sender, fee, '', params);
result = await this._submitTx(msg, privateKey, sender);
return parseTxResponse(result);
@ -384,9 +383,9 @@ export class Registry {
const msgParams = {
name: params.name,
owner: params.owner || sender.accountAddress
}
};
const msg = createTxMsgReserveAuthority(this._chain, sender, fee, '', msgParams)
const msg = createTxMsgReserveAuthority(this._chain, sender, fee, '', msgParams);
result = await this._submitTx(msg, privateKey, sender);
return parseTxResponse(result);
@ -400,7 +399,7 @@ export class Registry {
const account = new Account(Buffer.from(privateKey, 'hex'));
const sender = await this._getSender(account);
const msg = createTxMsgSetAuthorityBond(this._chain, sender, fee, '', params)
const msg = createTxMsgSetAuthorityBond(this._chain, sender, fee, '', params);
result = await this._submitTx(msg, privateKey, sender);
return parseTxResponse(result);
@ -414,7 +413,7 @@ export class Registry {
const account = new Account(Buffer.from(privateKey, 'hex'));
const sender = await this._getSender(account);
const msg = createTxMsgCommitBid(this._chain, sender, fee, '', params)
const msg = createTxMsgCommitBid(this._chain, sender, fee, '', params);
result = await this._submitTx(msg, privateKey, sender);
return parseTxResponse(result);
@ -428,7 +427,7 @@ export class Registry {
const account = new Account(Buffer.from(privateKey, 'hex'));
const sender = await this._getSender(account);
const msg = createTxMsgRevealBid(this._chain, sender, fee, '', params)
const msg = createTxMsgRevealBid(this._chain, sender, fee, '', params);
result = await this._submitTx(msg, privateKey, sender);
return parseTxResponse(result);
@ -456,7 +455,7 @@ export class Registry {
const account = new Account(Buffer.from(privateKey, 'hex'));
const sender = await this._getSender(account);
const msg = createTxMsgSetName(this._chain, sender, fee, '', params)
const msg = createTxMsgSetName(this._chain, sender, fee, '', params);
result = await this._submitTx(msg, privateKey, sender);
return parseTxResponse(result);
@ -477,7 +476,7 @@ export class Registry {
const account = new Account(Buffer.from(privateKey, 'hex'));
const sender = await this._getSender(account);
const msg = createTxMsgDeleteName(this._chain, sender, fee, '', params)
const msg = createTxMsgDeleteName(this._chain, sender, fee, '', params);
result = await this._submitTx(msg, privateKey, sender);
return parseTxResponse(result);
@ -524,7 +523,7 @@ export class Registry {
const account = new Account(Buffer.from(privateKey, 'hex'));
const sender = await this._getSender(account);
const msg = createTxMsgSetRecord(this._chain, sender, fee, '', params)
const msg = createTxMsgSetRecord(this._chain, sender, fee, '', params);
return this._submitTx(msg, privateKey, sender);
}
@ -543,7 +542,7 @@ export class Registry {
// Generate signed Tx.
const transaction = createTransaction(message, account, sender, this._chain);
const tx = generatePostBodyBroadcast(transaction, BroadcastMode.Block)
const tx = generatePostBodyBroadcast(transaction, BroadcastMode.Block);
// Submit Tx to chain.
const { tx_response: response } = await this._client.submit(tx);
@ -551,7 +550,7 @@ export class Registry {
if (response.code !== 0) {
// Throw error when transaction is not successful.
// https://docs.starport.com/guide/nameservice/05-play.html#buy-name-transaction-details
throw new Error(Registry.processWriteError(response.raw_log))
throw new Error(Registry.processWriteError(response.raw_log));
}
return response;
@ -561,10 +560,10 @@ export class Registry {
* https://evmos.dev/basics/chain_id.html
*/
_parseEthChainId (chainId: string) {
const [ idWithChainNumber ] = chainId.split('-')
const [ _, ethChainId ] = idWithChainNumber.split('_')
const [idWithChainNumber] = chainId.split('-');
const [_, ethChainId] = idWithChainNumber.split('_');
return Number(ethChainId)
return Number(ethChainId);
}
/**
@ -582,13 +581,13 @@ export class Registry {
accountAddress: account.formattedCosmosAddress,
sequence: sequence,
accountNumber: number,
pubkey: account.encodedPubkey,
}
pubkey: account.encodedPubkey
};
}
async getLaconicClient (account: Account) {
return LaconicClient.connectWithSigner(this._endpoints.rest, account.wallet)
return LaconicClient.connectWithSigner(this._endpoints.rest, account.wallet);
}
}
export { Account }
export { Account };

View File

@ -1,55 +1,45 @@
import { GeneratedType, OfflineSigner, Registry } from "@cosmjs/proto-signing";
import { GeneratedType, OfflineSigner, Registry } from '@cosmjs/proto-signing';
import {
defaultRegistryTypes,
DeliverTxResponse,
SigningStargateClient,
SigningStargateClientOptions,
StdFee,
} from "@cosmjs/stargate"
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";
StdFee
} from '@cosmjs/stargate';
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';
export const laconicDefaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
...defaultRegistryTypes,
...bondTypes,
]
...bondTypes
];
function createDefaultRegistry (): Registry {
return new Registry(laconicDefaultRegistryTypes);
}
export class LaconicClient extends SigningStargateClient {
public static async connectWithSigner (
endpoint: string,
signer: OfflineSigner,
options: SigningStargateClientOptions = {},
options: SigningStargateClientOptions = {}
): Promise<LaconicClient> {
const cometClient = await Comet38Client.connect(endpoint);
return new LaconicClient(cometClient, signer, {
registry: createDefaultRegistry(),
...options,
...options
});
}
protected constructor(
cometClient: Comet38Client,
signer: OfflineSigner,
options: SigningStargateClientOptions,
) {
super(cometClient, signer, options);
}
public async createBond (
signer: string,
denom: string,
amount: string,
fee: StdFee | "auto" | number,
memo = "",
fee: StdFee | 'auto' | number,
memo = ''
): Promise<DeliverTxResponse> {
const createMsg: MsgCreateBondEncodeObject = {
typeUrl: typeUrlMsgCreateBond,
@ -61,7 +51,7 @@ export class LaconicClient extends SigningStargateClient {
amount
})
]
},
}
};
return this.signAndBroadcast(signer, [createMsg], fee, memo);
@ -72,8 +62,8 @@ export class LaconicClient extends SigningStargateClient {
denom: string,
amount: string,
id: string,
fee: StdFee | "auto" | number,
memo = "",
fee: StdFee | 'auto' | number,
memo = ''
): Promise<DeliverTxResponse> {
const createMsg: MsgRefillBondEncodeObject = {
typeUrl: typeUrlMsgRefillBond,
@ -86,7 +76,7 @@ export class LaconicClient extends SigningStargateClient {
amount
})
]
},
}
};
return this.signAndBroadcast(signer, [createMsg], fee, memo);
@ -97,8 +87,8 @@ export class LaconicClient extends SigningStargateClient {
denom: string,
amount: string,
id: string,
fee: StdFee | "auto" | number,
memo = "",
fee: StdFee | 'auto' | number,
memo = ''
): Promise<DeliverTxResponse> {
const createMsg: MsgWithdrawBondEncodeObject = {
typeUrl: typeUrlMsgWithdrawBond,
@ -111,7 +101,7 @@ export class LaconicClient extends SigningStargateClient {
amount
})
]
},
}
};
return this.signAndBroadcast(signer, [createMsg], fee, memo);
@ -120,15 +110,15 @@ export class LaconicClient extends SigningStargateClient {
public async cancelBond (
signer: string,
id: string,
fee: StdFee | "auto" | number,
memo = "",
fee: StdFee | 'auto' | number,
memo = ''
): Promise<DeliverTxResponse> {
const createMsg: MsgCancelBondEncodeObject = {
typeUrl: typeUrlMsgCancelBond,
value: {
id,
signer
},
}
};
return this.signAndBroadcast(signer, [createMsg], fee, memo);

View File

@ -1,22 +1,22 @@
import {
generateTypes,
} from '@tharsis/eip712'
generateTypes
} from '@tharsis/eip712';
import {
Chain,
Sender,
Fee,
} from '@tharsis/transactions'
Fee
} from '@tharsis/transactions';
import * as auctionTx from '../proto/vulcanize/auction/v1beta1/tx'
import { createTx } from './util'
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' },
{ name: 'signer', type: 'string' }
]
}
};
export interface MessageMsgCommitBid {
auctionId: string,
@ -27,9 +27,9 @@ const MSG_REVEAL_BID_TYPES = {
MsgValue: [
{ name: 'auction_id', type: 'string' },
{ name: 'reveal', type: 'string' },
{ name: 'signer', type: 'string' },
{ name: 'signer', type: 'string' }
]
}
};
export interface MessageMsgRevealBid {
auctionId: string,
@ -41,23 +41,23 @@ export function createTxMsgCommitBid(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgCommitBid,
params: MessageMsgCommitBid
) {
const types = generateTypes(MSG_COMMIT_BID_TYPES)
const types = generateTypes(MSG_COMMIT_BID_TYPES);
const msg = createMsgCommitBid(
params.auctionId,
params.commitHash,
sender.accountAddress,
)
sender.accountAddress
);
const msgCosmos = protoCreateMsgCommitBid(
params.auctionId,
params.commitHash,
sender.accountAddress,
)
sender.accountAddress
);
return createTx(chain, sender, fee, memo, types, msg, msgCosmos)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgRevealBid (
@ -65,23 +65,23 @@ export function createTxMsgRevealBid(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgRevealBid,
params: MessageMsgRevealBid
) {
const types = generateTypes(MSG_REVEAL_BID_TYPES)
const types = generateTypes(MSG_REVEAL_BID_TYPES);
const msg = createMsgRevealBid(
params.auctionId,
params.reveal,
sender.accountAddress,
)
sender.accountAddress
);
const msgCosmos = protoCreateMsgRevealBid(
params.auctionId,
params.reveal,
sender.accountAddress,
)
sender.accountAddress
);
return createTx(chain, sender, fee, memo, types, msg, msgCosmos)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
function createMsgCommitBid (
@ -94,9 +94,9 @@ function createMsgCommitBid(
value: {
auction_id: auctionId,
commit_hash: commitHash,
signer,
},
signer
}
};
}
const protoCreateMsgCommitBid = (
@ -107,14 +107,14 @@ const protoCreateMsgCommitBid = (
const commitBidMessage = new auctionTx.vulcanize.auction.v1beta1.MsgCommitBid({
auction_id: auctionId,
commit_hash: commitHash,
signer,
})
signer
});
return {
message: commitBidMessage,
path: 'vulcanize.auction.v1beta1.MsgCommitBid',
}
}
path: 'vulcanize.auction.v1beta1.MsgCommitBid'
};
};
function createMsgRevealBid (
auctionId: string,
@ -126,9 +126,9 @@ function createMsgRevealBid(
value: {
auction_id: auctionId,
reveal,
signer,
},
signer
}
};
}
const protoCreateMsgRevealBid = (
@ -139,11 +139,11 @@ const protoCreateMsgRevealBid = (
const revealBidMessage = new auctionTx.vulcanize.auction.v1beta1.MsgRevealBid({
auction_id: auctionId,
reveal,
signer,
})
signer
});
return {
message: revealBidMessage,
path: 'vulcanize.auction.v1beta1.MsgRevealBid',
}
}
path: 'vulcanize.auction.v1beta1.MsgRevealBid'
};
};

View File

@ -1,88 +1,88 @@
import {
generateTypes,
} from '@tharsis/eip712'
generateTypes
} from '@tharsis/eip712';
import {
Chain,
Sender,
Fee,
} from '@tharsis/transactions'
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'
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[]' },
{ name: 'coins', type: 'TypeCoins[]' }
],
TypeCoins: [
{ name: 'denom', type: 'string' },
{ name: 'amount', type: 'string' },
],
}
{ name: 'amount', type: 'string' }
]
};
const MSG_REFILL_BOND_TYPES = {
MsgValue: [
{ name: 'id', type: 'string' },
{ name: 'signer', type: 'string' },
{ name: 'coins', type: 'TypeCoins[]' },
{ name: 'coins', type: 'TypeCoins[]' }
],
TypeCoins: [
{ name: 'denom', type: 'string' },
{ name: 'amount', type: 'string' },
],
}
{ name: 'amount', type: 'string' }
]
};
const MSG_WITHDRAW_BOND_TYPES = {
MsgValue: [
{ name: 'id', type: 'string' },
{ name: 'signer', type: 'string' },
{ name: 'coins', type: 'TypeCoins[]' },
{ name: 'coins', type: 'TypeCoins[]' }
],
TypeCoins: [
{ name: 'denom', type: 'string' },
{ name: 'amount', type: 'string' },
],
}
{ name: 'amount', type: 'string' }
]
};
const MSG_CANCEL_BOND_TYPES = {
MsgValue: [
{ name: 'id', type: 'string' },
{ name: 'signer', 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' },
{ name: 'signer', type: 'string' }
]
}
};
const MSG_DISSOCIATE_BOND_TYPES = {
MsgValue: [
{ name: 'record_id', type: 'string' },
{ name: 'signer', type: 'string' },
{ name: 'signer', type: 'string' }
]
}
};
const MSG_DISSOCIATE_RECORDS_TYPES = {
MsgValue: [
{ name: 'bond_id', type: 'string' },
{ name: 'signer', 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' },
{ name: 'signer', type: 'string' }
]
}
};
export interface MessageMsgCreateBond {
amount: string
@ -128,23 +128,23 @@ export function createTxMsgCreateBond(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgCreateBond,
params: MessageMsgCreateBond
) {
const types = generateTypes(MSG_CREATE_BOND_TYPES)
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)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgRefillBond (
@ -152,25 +152,25 @@ export function createTxMsgRefillBond(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgRefillBond,
params: MessageMsgRefillBond
) {
const types = generateTypes(MSG_REFILL_BOND_TYPES)
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)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgWithdrawBond (
@ -178,25 +178,25 @@ export function createTxMsgWithdrawBond(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgWithdrawBond,
params: MessageMsgWithdrawBond
) {
const types = generateTypes(MSG_WITHDRAW_BOND_TYPES)
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)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgCancelBond (
@ -204,21 +204,21 @@ export function createTxMsgCancelBond(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgCancelBond,
params: MessageMsgCancelBond
) {
const types = generateTypes(MSG_CANCEL_BOND_TYPES)
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)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgAssociateBond (
@ -226,23 +226,23 @@ export function createTxMsgAssociateBond(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgAssociateBond,
params: MessageMsgAssociateBond
) {
const types = generateTypes(MSG_ASSOCIATE_BOND_TYPES)
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)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgDissociateBond (
@ -250,21 +250,21 @@ export function createTxMsgDissociateBond(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgDissociateBond,
params: MessageMsgDissociateBond
) {
const types = generateTypes(MSG_DISSOCIATE_BOND_TYPES)
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)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgDissociateRecords (
@ -272,21 +272,21 @@ export function createTxMsgDissociateRecords(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgDissociateRecords,
params: MessageMsgDissociateRecords
) {
const types = generateTypes(MSG_DISSOCIATE_RECORDS_TYPES)
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)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgReAssociateRecords (
@ -294,29 +294,29 @@ export function createTxMsgReAssociateRecords(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgReAssociateRecords,
params: MessageMsgReAssociateRecords
) {
const types = generateTypes(MSG_REASSOCIATE_RECORDS_TYPES)
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)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
function createMsgCreateBond (
signer: string,
amount: string,
denom: string,
denom: string
) {
return {
type: 'bond/MsgCreateBond',
@ -324,40 +324,40 @@ function createMsgCreateBond(
coins: [
{
amount,
denom,
},
denom
}
],
signer
},
}
};
}
const protoCreateMsgCreateBond = (
signer: string,
amount: string,
denom: string,
denom: string
) => {
const value = new coin.cosmos.base.v1beta1.Coin({
denom,
amount,
})
amount
});
const createBondMessage = new bondTx.vulcanize.bond.v1beta1.MsgCreateBond({
signer,
coins: [value]
})
});
return {
message: createBondMessage,
path: 'vulcanize.bond.v1beta1.MsgCreateBond',
}
}
path: 'vulcanize.bond.v1beta1.MsgCreateBond'
};
};
function createMsgRefillBond (
id: string,
signer: string,
amount: string,
denom: string,
denom: string
) {
return {
type: 'bond/MsgRefillBond',
@ -365,43 +365,43 @@ function createMsgRefillBond(
coins: [
{
amount,
denom,
},
denom
}
],
id,
signer
},
}
};
}
const protoCreateMsgRefillBond = (
id: string,
signer: string,
amount: string,
denom: string,
denom: string
) => {
const value = new coin.cosmos.base.v1beta1.Coin({
denom,
amount,
})
amount
});
const refillBondMessage = new bondTx.vulcanize.bond.v1beta1.MsgRefillBond({
id,
signer,
coins: [value]
})
});
return {
message: refillBondMessage,
path: 'vulcanize.bond.v1beta1.MsgRefillBond',
}
}
path: 'vulcanize.bond.v1beta1.MsgRefillBond'
};
};
function createMsgWithdrawBond (
id: string,
signer: string,
amount: string,
denom: string,
denom: string
) {
return {
type: 'bond/MsgWithdrawBond',
@ -410,36 +410,36 @@ function createMsgWithdrawBond(
coins: [
{
amount,
denom,
},
denom
}
],
signer
},
}
};
}
const protoCreateMsgWithdrawBond = (
id: string,
signer: string,
amount: string,
denom: string,
denom: string
) => {
const value = new coin.cosmos.base.v1beta1.Coin({
denom,
amount,
})
amount
});
const withdrawBondMessage = new bondTx.vulcanize.bond.v1beta1.MsgWithdrawBond({
id,
signer,
coins: [value]
})
});
return {
message: withdrawBondMessage,
path: 'vulcanize.bond.v1beta1.MsgWithdrawBond',
}
}
path: 'vulcanize.bond.v1beta1.MsgWithdrawBond'
};
};
function createMsgCancelBond (
id: string,
@ -450,8 +450,8 @@ function createMsgCancelBond(
value: {
id,
signer
},
}
};
}
const protoCreateMsgCancelBond = (
@ -461,13 +461,13 @@ const protoCreateMsgCancelBond = (
const cancelBondMessage = new bondTx.vulcanize.bond.v1beta1.MsgCancelBond({
id,
signer
})
});
return {
message: cancelBondMessage,
path: 'vulcanize.bond.v1beta1.MsgCancelBond',
}
}
path: 'vulcanize.bond.v1beta1.MsgCancelBond'
};
};
function createMsgAssociateBond (
recordId: string,
@ -480,8 +480,8 @@ function createMsgAssociateBond(
record_id: recordId,
bond_id: bondId,
signer
},
}
};
}
const protoCreateMsgAssociateBond = (
@ -493,13 +493,13 @@ const protoCreateMsgAssociateBond = (
record_id: recordId,
bond_id: bondId,
signer
})
});
return {
message: associateBondMessage,
path: 'vulcanize.registry.v1beta1.MsgAssociateBond',
}
}
path: 'vulcanize.registry.v1beta1.MsgAssociateBond'
};
};
function createMsgDissociateBond (
recordId: string,
@ -510,8 +510,8 @@ function createMsgDissociateBond(
value: {
record_id: recordId,
signer
},
}
};
}
const protoCreateMsgDissociateBond = (
@ -521,13 +521,13 @@ const protoCreateMsgDissociateBond = (
const dissociateBondMessage = new registryTx.vulcanize.registry.v1beta1.MsgDissociateBond({
record_id: recordId,
signer
})
});
return {
message: dissociateBondMessage,
path: 'vulcanize.registry.v1beta1.MsgDissociateBond',
}
}
path: 'vulcanize.registry.v1beta1.MsgDissociateBond'
};
};
function createMsgDissociateRecords (
bondId: string,
@ -538,8 +538,8 @@ function createMsgDissociateRecords(
value: {
bond_id: bondId,
signer
},
}
};
}
const protoCreateMsgDissociateRecords = (
@ -549,13 +549,13 @@ const protoCreateMsgDissociateRecords = (
const dissociateRecordsMessage = new registryTx.vulcanize.registry.v1beta1.MsgDissociateRecords({
bond_id: bondId,
signer
})
});
return {
message: dissociateRecordsMessage,
path: 'vulcanize.registry.v1beta1.MsgDissociateRecords',
}
}
path: 'vulcanize.registry.v1beta1.MsgDissociateRecords'
};
};
function createMsgReAssociateRecords (
newBondId: string,
@ -568,8 +568,8 @@ function createMsgReAssociateRecords(
new_bond_id: newBondId,
old_bond_id: oldBondId,
signer
},
}
};
}
const protoCreateMsgReAssociateRecords = (
@ -581,10 +581,10 @@ const protoCreateMsgReAssociateRecords = (
new_bond_id: newBondId,
old_bond_id: oldBondId,
signer
})
});
return {
message: reAssociateRecordsMessage,
path: 'vulcanize.registry.v1beta1.MsgReAssociateRecords',
}
}
path: 'vulcanize.registry.v1beta1.MsgReAssociateRecords'
};
};

View File

@ -1,42 +1,42 @@
import {
generateTypes,
} from '@tharsis/eip712'
generateTypes
} from '@tharsis/eip712';
import {
Chain,
Sender,
Fee,
} from '@tharsis/transactions'
Fee
} from '@tharsis/transactions';
import * as registryTx from '../proto/vulcanize/registry/v1beta1/tx'
import * as registry from '../proto/vulcanize/registry/v1beta1/registry'
import { createTx } from './util'
import { Payload } from '../types'
import * as registryTx from '../proto/vulcanize/registry/v1beta1/tx';
import * as registry from '../proto/vulcanize/registry/v1beta1/registry';
import { createTx } from './util';
import { Payload } from '../types';
const MSG_RESERVE_AUTHORITY_TYPES = {
MsgValue: [
{ name: 'name', type: 'string' },
{ name: 'signer', type: 'string' },
{ name: 'owner', type: 'string' },
],
}
{ name: 'owner', type: 'string' }
]
};
const MSG_SET_NAME_TYPES = {
MsgValue: [
{ name: 'crn', type: 'string' },
{ name: 'cid', type: 'string' },
{ name: 'signer', 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' },
{ name: 'payload', type: 'TypePayload' }
],
TypePayload: [
{ name: 'record', type: 'TypePayloadRecord' },
{ name: 'signatures', type: 'TypePayloadSignatures[]' },
{ name: 'signatures', type: 'TypePayloadSignatures[]' }
],
TypePayloadRecord: [
{ name: 'id', type: 'string' },
@ -44,48 +44,48 @@ const MSG_SET_RECORD_TYPES = {
{ name: 'create_time', type: 'string' },
{ name: 'expiry_time', type: 'string' },
{ name: 'deleted', type: 'bool' },
{ name: 'attributes', type: 'bytes' },
{ 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' },
],
}
{ name: 'signer', type: 'string' }
]
};
const MSG_DELETE_NAME_TYPES = {
MsgValue: [
{ name: 'crn', type: 'string' },
{ name: 'signer', type: 'string' },
],
}
{ name: 'signer', type: 'string' }
]
};
export const parseMsgSetRecordResponse = (data: string) => {
const responseBytes = Buffer.from(data, 'hex')
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(';')
const [_, id] = responseBytes.toString().split(';');
return { id }
}
return { id };
};
export const NAMESERVICE_ERRORS = [
'Name already reserved.',
'Authority bond not found.',
'Name authority not found.',
'Access denied.',
]
'Access denied.'
];
export interface MessageMsgReserveAuthority {
name: string
@ -116,23 +116,23 @@ export function createTxMsgReserveAuthority(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgReserveAuthority,
params: MessageMsgReserveAuthority
) {
const types = generateTypes(MSG_RESERVE_AUTHORITY_TYPES)
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)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgSetName (
@ -140,23 +140,23 @@ export function createTxMsgSetName(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgSetName,
params: MessageMsgSetName
) {
const types = generateTypes(MSG_SET_NAME_TYPES)
const types = generateTypes(MSG_SET_NAME_TYPES);
const msg = createMsgSetName(
params.crn,
params.cid,
sender.accountAddress
)
);
const msgCosmos = protoCreateMsgSetName(
params.crn,
params.cid,
sender.accountAddress
)
);
return createTx(chain, sender, fee, memo, types, msg, msgCosmos)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgSetRecord (
@ -164,23 +164,23 @@ export function createTxMsgSetRecord(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgSetRecord,
params: MessageMsgSetRecord
) {
const types = generateTypes(MSG_SET_RECORD_TYPES)
const types = generateTypes(MSG_SET_RECORD_TYPES);
const msg = createMsgSetRecord(
params.bondId,
params.payload,
sender.accountAddress
)
);
const msgCosmos = protoCreateMsgSetRecord(
params.bondId,
params.payload,
sender.accountAddress
)
);
return createTx(chain, sender, fee, memo, types, msg, msgCosmos)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgSetAuthorityBond (
@ -188,23 +188,23 @@ export function createTxMsgSetAuthorityBond(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgSetAuthorityBond,
params: MessageMsgSetAuthorityBond
) {
const types = generateTypes(MSG_SET_AUTHORITY_BOND_TYPES)
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)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
export function createTxMsgDeleteName (
@ -212,21 +212,21 @@ export function createTxMsgDeleteName(
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgDeleteName,
params: MessageMsgDeleteName
) {
const types = generateTypes(MSG_DELETE_NAME_TYPES)
const types = generateTypes(MSG_DELETE_NAME_TYPES);
const msg = createMsgDeleteName(
params.crn,
sender.accountAddress
)
);
const msgCosmos = protoCreateMsgDeleteName(
params.crn,
sender.accountAddress
)
);
return createTx(chain, sender, fee, memo, types, msg, msgCosmos)
return createTx(chain, sender, fee, memo, types, msg, msgCosmos);
}
function createMsgReserveAuthority (
@ -240,26 +240,26 @@ function createMsgReserveAuthority(
name,
signer,
owner
},
}
};
}
const protoCreateMsgReserveAuthority = (
name: string,
signer: string,
owner: string,
owner: string
) => {
const reserveAuthorityMessage = new registryTx.vulcanize.registry.v1beta1.MsgReserveAuthority({
name,
signer,
owner
})
});
return {
message: reserveAuthorityMessage,
path: 'vulcanize.registry.v1beta1.MsgReserveAuthority',
}
}
path: 'vulcanize.registry.v1beta1.MsgReserveAuthority'
};
};
function createMsgSetName (
crn: string,
@ -272,8 +272,8 @@ function createMsgSetName(
crn,
cid,
signer
},
}
};
}
const protoCreateMsgSetName = (
@ -284,14 +284,14 @@ const protoCreateMsgSetName = (
const setNameMessage = new registryTx.vulcanize.registry.v1beta1.MsgSetName({
crn,
cid,
signer,
})
signer
});
return {
message: setNameMessage,
path: 'vulcanize.registry.v1beta1.MsgSetName',
}
}
path: 'vulcanize.registry.v1beta1.MsgSetName'
};
};
function createMsgSetRecord (
bondId: string,
@ -304,8 +304,8 @@ function createMsgSetRecord(
bond_id: bondId,
signer,
payload: payload.serialize()
},
}
};
}
const protoCreateMsgSetRecord = (
@ -313,30 +313,30 @@ const protoCreateMsgSetRecord = (
payloadData: Payload,
signer: string
) => {
const record = new registry.vulcanize.registry.v1beta1.Record(payloadData.record.serialize())
const record = new registry.vulcanize.registry.v1beta1.Record(payloadData.record.serialize());
const signatures = payloadData.signatures.map(
signature => new registry.vulcanize.registry.v1beta1.Signature(
signature.serialize()
)
)
);
const payload = new registryTx.vulcanize.registry.v1beta1.Payload({
record,
signatures
})
});
const setNameMessage = new registryTx.vulcanize.registry.v1beta1.MsgSetRecord({
bond_id: bondId,
signer,
payload
})
});
return {
message: setNameMessage,
path: 'vulcanize.registry.v1beta1.MsgSetRecord',
}
}
path: 'vulcanize.registry.v1beta1.MsgSetRecord'
};
};
function createMsgSetAuthorityBond (
name: string,
@ -349,8 +349,8 @@ function createMsgSetAuthorityBond(
name,
bond_id: bondId,
signer
},
}
};
}
const protoCreateMsgSetAuthorityBond = (
@ -361,14 +361,14 @@ const protoCreateMsgSetAuthorityBond = (
const setAuthorityBondMessage = new registryTx.vulcanize.registry.v1beta1.MsgSetAuthorityBond({
name,
bond_id: bondId,
signer,
})
signer
});
return {
message: setAuthorityBondMessage,
path: 'vulcanize.registry.v1beta1.MsgSetAuthorityBond',
}
}
path: 'vulcanize.registry.v1beta1.MsgSetAuthorityBond'
};
};
function createMsgDeleteName (
crn: string,
@ -379,8 +379,8 @@ function createMsgDeleteName(
value: {
crn,
signer
},
}
};
}
const protoCreateMsgDeleteName = (
@ -389,11 +389,11 @@ const protoCreateMsgDeleteName = (
) => {
const deleteNameAutorityMessage = new registryTx.vulcanize.registry.v1beta1.MsgDeleteNameAuthority({
crn,
signer,
})
signer
});
return {
message: deleteNameAutorityMessage,
path: 'vulcanize.registry.v1beta1.MsgDeleteNameAuthority',
}
}
path: 'vulcanize.registry.v1beta1.MsgDeleteNameAuthority'
};
};

View File

@ -1,16 +1,16 @@
import { Message } from "google-protobuf";
import { Message } from 'google-protobuf';
import {
createEIP712,
generateFee,
generateMessage,
generateTypes,
} from '@tharsis/eip712'
generateTypes
} from '@tharsis/eip712';
import {
Chain,
Sender,
Fee,
} from '@tharsis/transactions'
import { createTransaction } from '@tharsis/proto'
Fee
} from '@tharsis/transactions';
import { createTransaction } from '@tharsis/proto';
interface Msg {
type: string
@ -36,16 +36,16 @@ export const createTx = (
memo: string,
messageTypes: Types,
msg: Msg,
msgCosmos: MsgCosmos,
msgCosmos: MsgCosmos
) => {
// EIP712
const feeObject = generateFee(
fee.amount,
fee.denom,
fee.gas,
sender.accountAddress,
)
const types = generateTypes(messageTypes)
sender.accountAddress
);
const types = generateTypes(messageTypes);
const messages = generateMessage(
sender.accountNumber.toString(),
@ -53,9 +53,9 @@ export const createTx = (
chain.cosmosChainId,
memo,
feeObject,
msg,
)
const eipToSign = createEIP712(types, chain.chainId, messages)
msg
);
const eipToSign = createEIP712(types, chain.chainId, messages);
// Cosmos
const tx = createTransaction(
@ -68,12 +68,12 @@ export const createTx = (
sender.pubkey,
sender.sequence,
sender.accountNumber,
chain.cosmosChainId,
)
chain.cosmosChainId
);
return {
signDirect: tx.signDirect,
legacyAmino: tx.legacyAmino,
eipToSign,
}
}
eipToSign
};
};

View File

@ -38,8 +38,8 @@ const nameserviceExpiryTests = () => {
},
privateKey,
fee
)
console.log("SetRecordResult: " + result.data.id)
);
console.log('SetRecordResult: ' + result.data.id);
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
recordExpiryTime = new Date(record.expiryTime);
@ -47,7 +47,7 @@ const nameserviceExpiryTests = () => {
expect(bond).toBeDefined();
expect(bond.balance).toHaveLength(1);
expect(bond.balance[0].quantity).toBe('2000000');
})
});
test('Reserve authority and set bond', async () => {
authorityName = `laconic-${Date.now()}`;
@ -67,21 +67,21 @@ const nameserviceExpiryTests = () => {
const updatedExpiryTime = new Date();
expect(updatedExpiryTime.getTime()).toBeGreaterThan(recordExpiryTime.getTime());
recordExpiryTime = updatedExpiryTime;
})
});
test('Check authority expiry time', async () => {
const [authority] = await registry.lookupAuthorities([authorityName]);
const updatedExpiryTime = new Date();
expect(updatedExpiryTime.getTime()).toBeGreaterThan(authorityExpiryTime.getTime());
authorityExpiryTime = updatedExpiryTime;
})
});
test('Check bond balance', async () => {
const [bond] = await registry.getBondsByIds([bondId]);
console.log(bond)
console.log(bond);
expect(bond).toBeDefined();
expect(bond.balance).toHaveLength(0);
})
});
test('Wait for expiry duration', (done) => {
setTimeout(done, 60 * 1000);
@ -90,13 +90,13 @@ const nameserviceExpiryTests = () => {
test('Check record deleted without bond balance', async () => {
const records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
expect(records).toHaveLength(0);
})
});
test('Check authority expired without bond balance', async () => {
const [authority] = await registry.lookupAuthorities([authorityName]);
expect(authority.status).toBe('expired');
})
}
});
};
if (!process.env.TEST_NAMESERVICE_EXPIRY) {
// Required as jest complains if file has no tests.
@ -107,11 +107,10 @@ if (!process.env.TEST_NAMESERVICE_EXPIRY) {
TEST_REGISTRY_EXPIRY=true ./init.sh
Run tests:
yarn test:nameservice-expiry
*/
describe('Nameservice Expiry', nameserviceExpiryTests)
describe('Nameservice Expiry', nameserviceExpiryTests);
}

View File

@ -35,7 +35,7 @@ const namingTests = () => {
},
privateKey,
fee
)
);
watcherId = result.data.id;
});
@ -52,12 +52,11 @@ const namingTests = () => {
let crn: string;
beforeAll(async () => {
authorityName = `laconic-${Date.now()}`;
crn = `crn://${authorityName}/app/test`;
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
})
});
test('Lookup authority.', async () => {
const [record] = await registry.lookupAuthorities([authorityName]);
@ -77,8 +76,8 @@ const namingTests = () => {
});
test('Reserve already reserved authority', async () => {
await expect(registry.reserveAuthority({ name: authorityName }, privateKey, fee)).
rejects.toThrow('Name already reserved.');
await expect(registry.reserveAuthority({ name: authorityName }, privateKey, fee))
.rejects.toThrow('Name already reserved.');
});
test('Reserve sub-authority.', async () => {
@ -114,9 +113,9 @@ const namingTests = () => {
});
test('Set name for unbonded authority', async () => {
assert(watcherId)
await expect(registry.setName({ crn, cid: watcherId }, privateKey, fee)).
rejects.toThrow('Authority bond not found.');
assert(watcherId);
await expect(registry.setName({ crn, cid: watcherId }, privateKey, fee))
.rejects.toThrow('Authority bond not found.');
});
test('Set authority bond', async () => {
@ -203,7 +202,7 @@ const namingTests = () => {
},
privateKey,
fee
)
);
const updatedWatcherId = result.data.id;
await registry.setName({ crn, cid: updatedWatcherId }, privateKey, fee);

View File

@ -1,7 +1,7 @@
import assert from 'assert';
import axios from 'axios';
import graphqlClient from 'graphql.js'
import { get, set } from 'lodash'
import graphqlClient from 'graphql.js';
import { get, set } from 'lodash';
import { generateEndpointAccount, generateEndpointBroadcast } from '@tharsis/provider';
import { Util } from './util';
@ -97,8 +97,8 @@ const auctionFields = `
* Registry
*/
export class RegistryClient {
_restEndpoint: string
_graph: any
_restEndpoint: string;
_graph: any;
/**
* Get query result.
@ -266,7 +266,7 @@ export class RegistryClient {
all
};
let result = (await this._graph(query)(variables))['queryRecords'];
let result = (await this._graph(query)(variables)).queryRecords;
result = RegistryClient.prepareAttributes('attributes')(result);
return result;
@ -296,7 +296,7 @@ export class RegistryClient {
const result = await this._graph(query)(variables);
return result['lookupAuthorities'];
return result.lookupAuthorities;
}
/**
@ -341,7 +341,7 @@ export class RegistryClient {
const result = await this._graph(query)(variables);
return result['lookupNames'];
return result.lookupNames;
}
/**
@ -367,7 +367,7 @@ export class RegistryClient {
names
};
let result = (await this._graph(query)(variables))['resolveNames'];
let result = (await this._graph(query)(variables)).resolveNames;
result = RegistryClient.prepareAttributes('attributes')(result);
return result;
@ -430,7 +430,7 @@ export class RegistryClient {
const { data } = await axios.post(
`${this._restEndpoint}${generateEndpointBroadcast()}`,
tx
)
);
return data;
}

View File

@ -77,7 +77,7 @@ describe('Querying', () => {
expect(record.id).toBe(watcher.id);
// temp fix
expect(record.attributes.repo_registration_record_cid).toBeDefined();
expect(record.attributes.repo_registration_record_cid).toHaveProperty("/");
expect(record.attributes.repo_registration_record_cid["/"]).toHaveLength(46);
expect(record.attributes.repo_registration_record_cid).toHaveProperty('/');
expect(record.attributes.repo_registration_record_cid['/']).toHaveLength(46);
});
});

View File

@ -31,17 +31,17 @@ export const getConfig = () => {
fee: {
amount: '40',
denom: 'aphoton',
gas: '400000',
}
gas: '400000'
}
};
};
// TODO: Merge both config
export const getLaconic2Config = () => {
return {
fee: {
amount: [{ denom: "photon", amount: "40" }],
gas: "400000",
}
}
amount: [{ denom: 'photon', amount: '40' }],
gas: '400000'
}
};
};

View File

@ -4,7 +4,7 @@ import {
signatureToWeb3Extension,
Chain,
Sender
} from '@tharsis/transactions'
} from '@tharsis/transactions';
import { Account } from './account';
@ -18,8 +18,8 @@ export const createTransaction = (message: any, account: Account, sender: Sender
// Sign transaction.
const signature = account.sign(message);
let extension = signatureToWeb3Extension(chain, sender, signature)
let extension = signatureToWeb3Extension(chain, sender, signature);
// Create the txRaw.
return createTxRawEIP712(message.legacyAmino.body, message.legacyAmino.authInfo, extension)
return createTxRawEIP712(message.legacyAmino.body, message.legacyAmino.authInfo, extension);
};

View File

@ -8,7 +8,7 @@ import { Util } from './util';
* Record.
*/
export class Record {
_record: any
_record: any;
/**
* New Record.
@ -27,7 +27,7 @@ export class Record {
}
get attributes () {
return Buffer.from(JSON.stringify(this._record), 'binary')
return Buffer.from(JSON.stringify(this._record), 'binary');
}
/**
@ -35,14 +35,14 @@ export class Record {
*/
serialize () {
return {
'id': '_',
'bond_id': '_',
'create_time': '_',
'expiry_time': '_',
id: '_',
bond_id: '_',
create_time: '_',
expiry_time: '_',
// Setting deleted as false (zero value) throws error in EIP712 signature verification.
'deleted': true,
'attributes': this.attributes,
}
deleted: true,
attributes: this.attributes
};
}
/**
@ -57,8 +57,8 @@ export class Record {
* Record Signature.
*/
export class Signature {
_pubKey: string
_sig: string
_pubKey: string;
_sig: string;
/**
* New Signature.
@ -76,8 +76,8 @@ export class Signature {
*/
serialize () {
return Util.sortJSON({
'pub_key': this._pubKey,
'sig': this._sig
pub_key: this._pubKey,
sig: this._sig
});
}
}
@ -86,8 +86,8 @@ export class Signature {
* Message Payload.
*/
export class Payload {
_record: Record
_signatures: Signature[]
_record: Record;
_signatures: Signature[];
/**
* New Payload.
@ -123,8 +123,8 @@ export class Payload {
// return Util.sortJSON({
// });
return {
'record': this._record.serialize(),
'signatures': this._signatures.map(s => s.serialize())
}
record: this._record.serialize(),
signatures: this._signatures.map(s => s.serialize())
};
}
}

View File

@ -1,4 +1,4 @@
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing";
import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing';
import {
MsgCreateBond,
@ -9,17 +9,16 @@ import {
MsgRefillBondResponse,
MsgWithdrawBondResponse,
MsgCancelBondResponse
} from "../../../proto2/cerc/bond/v1/tx";
export const typeUrlMsgCreateBond = "/cerc.bond.v1.MsgCreateBond";
export const typeUrlMsgRefillBond = "/cerc.bond.v1.MsgRefillBond";
export const typeUrlMsgWithdrawBond = "/cerc.bond.v1.MsgWithdrawBond";
export const typeUrlMsgCancelBond = "/cerc.bond.v1.MsgCancelBond";
export const typeUrlMsgCreateBondResponse = "/cerc.bond.v1.MsgCreateBondResponse";
export const typeUrlMsgRefillBondResponse = "/cerc.bond.v1.MsgRefillBondResponse";
export const typeUrlMsgWithdrawBondResponse = "/cerc.bond.v1.MsgWithdrawBondResponse";
export const typeUrlMsgCancelBondResponse = "/cerc.bond.v1.MsgCancelBondResponse";
} from '../../../proto2/cerc/bond/v1/tx';
export const typeUrlMsgCreateBond = '/cerc.bond.v1.MsgCreateBond';
export const typeUrlMsgRefillBond = '/cerc.bond.v1.MsgRefillBond';
export const typeUrlMsgWithdrawBond = '/cerc.bond.v1.MsgWithdrawBond';
export const typeUrlMsgCancelBond = '/cerc.bond.v1.MsgCancelBond';
export const typeUrlMsgCreateBondResponse = '/cerc.bond.v1.MsgCreateBondResponse';
export const typeUrlMsgRefillBondResponse = '/cerc.bond.v1.MsgRefillBondResponse';
export const typeUrlMsgWithdrawBondResponse = '/cerc.bond.v1.MsgWithdrawBondResponse';
export const typeUrlMsgCancelBondResponse = '/cerc.bond.v1.MsgCancelBondResponse';
export const bondTypes: ReadonlyArray<[string, GeneratedType]> = [
[typeUrlMsgCreateBond, MsgCreateBond],
@ -29,25 +28,25 @@ export const bondTypes: ReadonlyArray<[string, GeneratedType]> = [
[typeUrlMsgWithdrawBond, MsgWithdrawBond],
[typeUrlMsgWithdrawBondResponse, MsgWithdrawBondResponse],
[typeUrlMsgCancelBond, MsgCancelBond],
[typeUrlMsgCancelBondResponse, MsgCancelBondResponse],
[typeUrlMsgCancelBondResponse, MsgCancelBondResponse]
];
export interface MsgCreateBondEncodeObject extends EncodeObject {
readonly typeUrl: "/cerc.bond.v1.MsgCreateBond";
readonly typeUrl: '/cerc.bond.v1.MsgCreateBond';
readonly value: Partial<MsgCreateBond>;
}
export interface MsgRefillBondEncodeObject extends EncodeObject {
readonly typeUrl: "/cerc.bond.v1.MsgRefillBond";
readonly typeUrl: '/cerc.bond.v1.MsgRefillBond';
readonly value: Partial<MsgRefillBond>;
}
export interface MsgWithdrawBondEncodeObject extends EncodeObject {
readonly typeUrl: "/cerc.bond.v1.MsgWithdrawBond";
readonly typeUrl: '/cerc.bond.v1.MsgWithdrawBond';
readonly value: Partial<MsgWithdrawBond>;
}
export interface MsgCancelBondEncodeObject extends EncodeObject {
readonly typeUrl: "/cerc.bond.v1.MsgCancelBond";
readonly typeUrl: '/cerc.bond.v1.MsgCancelBond';
readonly value: Partial<MsgCancelBond>;
}

View File

@ -34,15 +34,15 @@ const utilTests = () => {
},
privateKey,
fee
)
);
watcherId = result.data.id;
});
test('Generate content id.', async () => {
const cid = await Util.getContentId(watcher.record);
expect(cid).toBe(watcherId)
expect(cid).toBe(watcherId);
});
}
};
describe('Util', utilTests);

View File

@ -1,7 +1,7 @@
import * as Block from 'multiformats/block'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
import * as dagCBOR from '@ipld/dag-cbor'
import * as dagJSON from '@ipld/dag-json'
import * as Block from 'multiformats/block';
import { sha256 as hasher } from 'multiformats/hashes/sha2';
import * as dagCBOR from '@ipld/dag-cbor';
import * as dagJSON from '@ipld/dag-json';
/**
* Utils
@ -54,17 +54,17 @@ export class Util {
type = (obj % 1 === 0) ? 'int' : 'float';
return { [type]: obj };
case 'string':
return { 'string': obj };
return { string: obj };
case 'boolean':
return { 'boolean': obj };
return { boolean: obj };
case 'object':
if (obj['/'] !== undefined) {
return { 'link': obj['/'] };
return { link: obj['/'] };
}
if (obj instanceof Array) {
return { 'array': obj };
return { array: obj };
}
return { 'map': obj };
return { map: obj };
case 'undefined':
return undefined;
default:
@ -106,14 +106,14 @@ export class Util {
* Get record content ID.
*/
static async getContentId (record: any) {
const serialized = dagJSON.encode(record)
const recordData = dagJSON.decode(serialized)
const serialized = dagJSON.encode(record);
const recordData = dagJSON.decode(serialized);
const block = await Block.encode({
value: recordData,
codec: dagCBOR,
hasher
})
});
return block.cid.toString();
}

1352
yarn.lock

File diff suppressed because it is too large Load Diff