Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

🎨 Use iscn-js #1560

Merged
merged 9 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ export const FINAL_TOKENSALE_PERCENTAGE = 180;

export const BONUS_LOCK_UNTIL_DATE = 1540267200000;

export const GAS_ESTIMATOR_BUFFER = 50000;
export const GAS_ESTIMATOR_SLOP = 3.58;
export const GAS_ESTIMATOR_INTERCEPT = 99443.87;

export const TRUST_URL = 'https://links.trustwalletapp.com/a/key_live_lfvIpVeI9TFWxPCqwU8rZnogFqhnzs4D?&event=openURL&url=';

export const LIKER_LAND_APP_LINK = {
Expand Down
84 changes: 68 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@cosmjs/proto-signing": "^0.25.6",
"@cosmjs/stargate": "^0.25.6",
"@likecoin/abi-decoder": "^3.0.0",
"@likecoin/iscn-js": "0.0.7",
"@likecoin/iscn-message-types": "0.0.1",
"@likecoin/nuxt-google-optimize": "^0.5.3-like.10",
"@likecoin/secretd-js": "^0.2.0",
Expand Down Expand Up @@ -97,7 +98,7 @@
"axiosist": "^0.1.0",
"babel-eslint": "^10.0.1",
"backpack-core": "^0.8.3",
"chromedriver": "^92.0.1",
"chromedriver": "^94.0.0",
"eslint": "^5.11.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-import-resolver-webpack": "^0.10.1",
Expand Down
2 changes: 0 additions & 2 deletions util/cosmos/iscn/constant.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { EXTERNAL_URL } from '@/constant';

export const ISCN_GAS = 200000;
export const ISCN_REGISTRY_NAME = 'likecoin-chain';
export const ISCN_PUBLISHERS = {
matters: {
license: 'matters',
Expand Down
31 changes: 0 additions & 31 deletions util/cosmos/iscn/iscnQueryExtension.js

This file was deleted.

105 changes: 2 additions & 103 deletions util/cosmos/iscn/query.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,18 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
// eslint-disable-next-line import/no-extraneous-dependencies
import { decodeTxRaw } from '@cosmjs/proto-signing';
import { QueryClient, StargateClient } from '@cosmjs/stargate';
import { MsgCreateIscnRecord } from '@likecoin/iscn-message-types/dist/iscn/tx';
import BigNumber from 'bignumber.js';
import { StargateClient } from '@cosmjs/stargate';
import { parseISCNTxInfoFromIndexedTx } from '@likecoin/iscn-js';

import setupISCNExtension from './iscnQueryExtension';
import { timeout } from '@/util/misc';
import { EXTERNAL_URL } from '@/constant';

const ISCN_RPC_URL = `${EXTERNAL_URL}/api/cosmos/rpc`;

let queryClient;
let stargateClient;

async function initQueryClient() {
const tendermintClient = await Tendermint34Client.connect(ISCN_RPC_URL);
const client = QueryClient.withExtensions(
tendermintClient,
setupISCNExtension,
);
return client;
}

export async function getQueryClient() {
if (!queryClient) queryClient = await initQueryClient();
return queryClient;
}

export async function getApiClient() {
if (!stargateClient) stargateClient = await StargateClient.connect(ISCN_RPC_URL);
return stargateClient;
}

function parseISCNRecordFields(record) {
const {
stakeholders,
contentMetadata,
} = record;
return {
...record,
stakeholders: stakeholders.map((s) => {
if (s) {
const sString = Buffer.from(s).toString('utf-8');
if (sString) return JSON.parse(sString);
}
return s;
}),
contentMetadata: JSON.parse(Buffer.from(contentMetadata).toString('utf-8')),
};
}

export function parseISCNTxInfoFromTxSuccess(tx) {
const { transactionHash } = tx;
let iscnId;
if (tx.rawLog) {
const [log] = JSON.parse(tx.rawLog);
if (log) {
const ev = log.events.find(e => e.type === 'iscn_record');
if (ev) iscnId = ev.attributes[0].value;
}
}
return {
txHash: transactionHash,
iscnId,
};
}

export function parseISCNTxInfoFromIndexedTx(tx) {
const { tx: txBytes, rawLog } = tx;
const decodedTx = decodeTxRaw(txBytes);
const messages = decodedTx.body.messages.map((m) => {
if (m.typeUrl === '/likechain.iscn.MsgCreateIscnRecord') {
const msg = MsgCreateIscnRecord.decode(m.value);
if (msg.record) {
msg.record = parseISCNRecordFields(msg.record);
}
return {
...m,
value: msg,
};
}
return null;
});

return {
...tx,
logs: JSON.parse(rawLog),
tx: {
...decodedTx,
body: {
...decodedTx.body,
messages: messages.filter(m => m),
},
},
};
}

export async function getISCNTransferInfo(txHash, opt) {
const apiClient = await getApiClient();
const { blocking } = opt;
Expand Down Expand Up @@ -206,19 +121,3 @@ export async function getISCNTransactionCompleted(txHash) {
isFailed: (code && code !== '0') || !success,
};
}

export async function queryFeePerByte() {
queryClient = await getQueryClient();
const res = await queryClient.iscn.params();
if (res && res.params && res.params.feePerByte) {
const {
denom,
amount,
} = res.params.feePerByte;
return {
denom,
amount: new BigNumber(amount).shiftedBy(-18).toFixed(),
};
}
return 0;
}
Loading