Skip to content

Commit 906d05f

Browse files
authored
Merge pull request #24 from cybercongress/feat/update-cosmjs-refactor
Feat/update cosmjs refactor
2 parents 5267b14 + df34899 commit 906d05f

17 files changed

+438
-335
lines changed

.eslintrc.js

+50-50
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
11
module.exports = {
2-
"env": {
3-
"es6": true,
4-
"jasmine": true,
5-
"node": true,
6-
"worker": true,
2+
env: {
3+
es6: true,
4+
jasmine: true,
5+
node: true,
6+
worker: true,
77
},
8-
"parser": "@typescript-eslint/parser",
9-
"parserOptions": {
10-
"ecmaVersion": 2018,
11-
"project": "./tsconfig.eslint.json",
8+
parser: "@typescript-eslint/parser",
9+
parserOptions: {
10+
ecmaVersion: 2020,
11+
project: "../tsconfig.eslint.json",
1212
},
13-
"plugins": ["@typescript-eslint", "prettier", "simple-import-sort", "import"],
14-
"extends": [
13+
plugins: ["@typescript-eslint", "prettier", "simple-import-sort", "import"],
14+
extends: [
1515
"eslint:recommended",
1616
"plugin:@typescript-eslint/recommended",
1717
"prettier",
1818
"plugin:prettier/recommended",
1919
"plugin:import/typescript",
2020
],
21-
"rules": {
22-
"curly": ["warn", "multi-line", "consistent"],
21+
rules: {
22+
curly: ["warn", "multi-line", "consistent"],
2323
"no-bitwise": "warn",
24-
"no-console": ["warn", { "allow": ["error", "info", "table", "warn"] }],
24+
"no-console": ["warn", { allow: ["error", "info", "table", "warn"] }],
2525
"no-param-reassign": "warn",
2626
"no-shadow": "off", // disabled in favour of @typescript-eslint/no-shadow, see https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
2727
"no-unused-vars": "off", // disabled in favour of @typescript-eslint/no-unused-vars, see https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md
2828
"prefer-const": "warn",
29-
"radix": ["warn", "always"],
30-
"spaced-comment": ["warn", "always", { "line": { "markers": ["/ <reference"] } }],
29+
radix: ["warn", "always"],
30+
"spaced-comment": ["warn", "always", { line: { markers: ["/ <reference"] } }],
3131
"import/no-cycle": "warn",
3232
"simple-import-sort/imports": "warn",
33-
"@typescript-eslint/array-type": ["warn", { "default": "array-simple" }],
33+
"@typescript-eslint/array-type": ["warn", { default: "array-simple" }],
3434
"@typescript-eslint/await-thenable": "warn",
3535
"@typescript-eslint/ban-types": "warn",
36-
"@typescript-eslint/explicit-function-return-type": ["warn", { "allowExpressions": true }],
36+
"@typescript-eslint/explicit-function-return-type": ["warn", { allowExpressions: true }],
3737
"@typescript-eslint/explicit-member-accessibility": "warn",
38-
"@typescript-eslint/naming-convention": [
39-
"warn",
40-
{
41-
"selector": "default",
42-
"format": ["strictCamelCase"],
43-
},
44-
{
45-
"selector": "typeLike",
46-
"format": ["StrictPascalCase"],
47-
},
48-
{
49-
"selector": "enumMember",
50-
"format": ["StrictPascalCase"],
51-
},
52-
{
53-
"selector": "variable",
54-
"format": ["strictCamelCase"],
55-
"leadingUnderscore": "allow",
56-
},
57-
{
58-
"selector": "parameter",
59-
"format": ["strictCamelCase"],
60-
"leadingUnderscore": "allow",
61-
},
62-
],
38+
// "@typescript-eslint/naming-convention": [
39+
// "warn",
40+
// {
41+
// selector: "default",
42+
// format: ["strictCamelCase"],
43+
// },
44+
// {
45+
// selector: "typeLike",
46+
// format: ["StrictPascalCase"],
47+
// },
48+
// {
49+
// selector: "enumMember",
50+
// format: ["StrictPascalCase"],
51+
// },
52+
// {
53+
// selector: "variable",
54+
// format: ["strictCamelCase"],
55+
// leadingUnderscore: "allow",
56+
// },
57+
// {
58+
// selector: "parameter",
59+
// format: ["strictCamelCase"],
60+
// leadingUnderscore: "allow",
61+
// },
62+
// ],
6363
"@typescript-eslint/no-dynamic-delete": "warn",
6464
"@typescript-eslint/no-empty-function": "off",
6565
"@typescript-eslint/no-empty-interface": "off",
6666
"@typescript-eslint/no-explicit-any": "off",
6767
"@typescript-eslint/no-floating-promises": "warn",
6868
"@typescript-eslint/no-parameter-properties": "warn",
6969
"@typescript-eslint/no-shadow": "warn",
70-
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
70+
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }],
7171
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
7272
"@typescript-eslint/no-use-before-define": "warn",
7373
"@typescript-eslint/prefer-readonly": "warn",
7474
},
75-
"overrides": [
75+
overrides: [
7676
{
77-
"files": "**/*.js",
78-
"rules": {
77+
files: "**/*.js",
78+
rules: {
7979
"@typescript-eslint/no-var-requires": "off",
8080
"@typescript-eslint/explicit-function-return-type": "off",
8181
"@typescript-eslint/explicit-member-accessibility": "off",
8282
},
8383
},
8484
{
85-
"files": "**/*.spec.ts",
86-
"rules": {
85+
files: "**/*.spec.ts",
86+
rules: {
8787
"@typescript-eslint/no-non-null-assertion": "off",
8888
},
8989
},
9090
],
91-
}
91+
};

.prettierignore

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ build/
44
custom_types/
55
dist/
66
docs/
7-
examples/
87
generated/
98
proto/
109
types/

examples/consts.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const rpcUrl = "http://localhost:26657";
2+
const validatorMnemonic =
3+
"satisfy adjust timber high purchase tuition stool faith fine install that you unaware feed domain license impose boss human eager hat rent enjoy dawn";
4+
// const neuronValidator = "bostrom1phaxpevm5wecex2jyaqty2a4v02qj7qm5n94ug";
5+
const prefix = "bostrom";
6+
7+
export { rpcUrl, validatorMnemonic, prefix };

examples/utils.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
2+
import { SigningCyberClient } from "../build/index";
3+
import { rpcUrl, prefix } from "./consts";
4+
5+
export async function createSigner(mnemonic: string) {
6+
const signer = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: prefix });
7+
const signerClient = await SigningCyberClient.connectWithSigner(rpcUrl, signer);
8+
9+
const address = (await signer.getAccounts())[0].address;
10+
return { address, signerClient };
11+
}

examples/workflowCyberlink.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { rpcUrl, validatorMnemonic } from "./consts";
2+
import { CyberClient } from "../build/index";
3+
import { createSigner } from "./utils";
4+
5+
async function main() {
6+
const queryClient = await CyberClient.connect(rpcUrl);
7+
const { address, signerClient } = await createSigner(validatorMnemonic);
8+
console.log(address);
9+
10+
const link1 = "QmWQixYeubM54RFHunos6K6aYYb1EE4XY6pBVDJtTNGr9D";
11+
const link2 = "QmQSbpPKGQgGMfgeFeQz9ATNrFJvi4oZ4KxtAJcnKuBwr5";
12+
const linkResult = await signerClient.cyberlink(address, link1, link2, "auto");
13+
console.log("Link: ", linkResult);
14+
15+
const rankResult = await queryClient.search(link1);
16+
console.log("Rank1:\r\n ", rankResult);
17+
18+
const searchResult = await queryClient.search(link1);
19+
console.log("Search:\r\n ", searchResult);
20+
}
21+
22+
main().then(
23+
() => process.exit(0),
24+
(error) => {
25+
console.error(error);
26+
process.exit(1);
27+
},
28+
);

examples/workflowInvestmint.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { rpcUrl, validatorMnemonic } from "./consts";
2+
import { CyberClient } from "../build/index";
3+
import { createSigner } from "./utils";
4+
5+
const BASE_VESTING_TIME = 86401;
6+
7+
async function main() {
8+
const queryClient = await CyberClient.connect(rpcUrl);
9+
const { address, signerClient } = await createSigner(validatorMnemonic);
10+
console.log(address);
11+
console.log("Balance:");
12+
var balanceResult = await queryClient.getAllBalances(address);
13+
console.log(balanceResult);
14+
15+
const vCoin = { denom: "hydrogen", amount: "1000000000" };
16+
const aCoin = { denom: "hydrogen", amount: "1000000000" };
17+
const vestingLength = BASE_VESTING_TIME * 100;
18+
19+
const vResult = await signerClient.investmint(address, vCoin, "millivolt", vestingLength, "auto");
20+
console.log("Investmint V - ", vResult);
21+
22+
const aResult = await signerClient.investmint(address, aCoin, "milliampere", vestingLength, "auto");
23+
console.log("Investmint A - ", aResult);
24+
}
25+
26+
main().then(
27+
() => process.exit(0),
28+
(error) => {
29+
console.error(error);
30+
process.exit(1);
31+
},
32+
);

0 commit comments

Comments
 (0)