Skip to content

Commit

Permalink
Merge pull request #751 from alleslabs/fix/tx-bug-remove-stone-12-1
Browse files Browse the repository at this point in the history
fix: tx logs and stone-12-1
  • Loading branch information
songwongtp committed Jan 26, 2024
2 parents c2b9a7a + cc80589 commit dc4089c
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 142 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

- [#751](https://github.com/alleslabs/celatone-frontend/pull/751) Fix fail txs should have no logs and remove stone-12-1

## v1.5.1

### Improvements
Expand Down
50 changes: 0 additions & 50 deletions src/config/chain/initia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,56 +156,6 @@ export const INITIA_CHAIN_CONFIGS: ChainConfigs = {
},
extra: { disableDelegation: true },
},
"stone-12-1": {
chain: "initia",
registryChainName: "initiatestnet12-1",
prettyName: "Initia Testnet 12-1",
lcd: "https://next-stone-rest.initia.tech",
rpc: "https://next-stone-rpc.initia.tech:443",
indexer: "https://stone-12-1-nft-graphql.alleslabs.dev/v1/graphql",
wallets: [...initiaWallets, ...keplrWallets],
features: {
faucet: {
enabled: true,
url: process.env.NEXT_PUBLIC_INITIA_TESTNET_FAUCET_URL ?? "",
},
wasm: {
enabled: false,
},
move: {
enabled: true,
moduleMaxFileSize: 1_048_576,
decodeApi: INITIA_DECODER,
verify: "https://stone-compiler.initia.tech/contracts/verify",
},
pool: {
enabled: false,
},
publicProject: {
enabled: true,
},
gov: {
enabled: true,
hideOpenProposal: true,
},
nft: {
enabled: true,
},
},
gas: {
gasPrice: {
tokenPerGas: 0.151,
denom: "uinit",
},
gasAdjustment: 1.5,
maxGasLimit: 25_000_000,
},
explorerLink: {
validator: "https://next.app.initia.tech/validator",
proposal: "https://next.app.initia.tech/proposal",
},
extra: {},
},
"stone-13": {
chain: "initia",
registryChainName: "initiatestnet13",
Expand Down
70 changes: 0 additions & 70 deletions src/lib/chain-registry/initiatestnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,53 +136,6 @@ export const initiatestnet: Chain[] = [
],
},
},
{
$schema: CHAIN_SCHEMA,
chain_name: "initiatestnet12-1",
status: "live",
network_type: "testnet",
pretty_name: "Initia Testnet 12-1",
chain_id: "stone-12-1",
bech32_prefix: "init",
daemon_name: "initiad",
node_home: NODE_HOME,
key_algos: ["secp256k1"],
slip44: 118,
fees: {
fee_tokens: [
{
denom: "uinit",
fixed_min_gas_price: 0,
low_gas_price: 0.151,
average_gas_price: 0.151,
high_gas_price: 0.151,
},
],
},
staking: {
staking_tokens: [
{
denom: "uinit",
},
],
},
logo_URIs: {
png: "",
svg: "",
},
apis: {
rpc: [
{
address: "https://next-stone-rpc.initia.tech:443",
},
],
rest: [
{
address: "https://next-stone-rest.initia.tech",
},
],
},
},
{
$schema: CHAIN_SCHEMA,
chain_name: "initiatestnet13",
Expand Down Expand Up @@ -306,29 +259,6 @@ export const initiatestnetAssets: AssetList[] = [
},
],
},
{
$schema: ASSETLIST_SCHEMA,
chain_name: "initiatestnet12-1",
assets: [
{
description: "The native staking token of Initia.",
denom_units: [
{
denom: "uinit",
exponent: 0,
},
{
denom: "init",
exponent: 6,
},
],
base: "uinit",
name: "Init",
display: "init",
symbol: "INIT",
},
],
},
{
$schema: ASSETLIST_SCHEMA,
chain_name: "initiatestnet13",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pages/tx-details/components/MessageSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const MessageSection = ({ txData }: MessageSectionProps) => {
</Flex>
{messages.map((msg, idx) => (
<TxMessage
key={msg.type + msg.value + logs[idx].msg_index.toString()}
key={msg.type + msg.value + idx.toString()}
msgBody={msg}
log={logs[idx]}
isSingleMsg={messages.length === 1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const TxMsgExpand = ({

const { "@type": type, ...body } = msgBody;
const isIBC =
Boolean(log.events.find((event) => event.type === "send_packet")) ||
Boolean(log?.events.find((event) => event.type === "send_packet")) ||
type.startsWith("/ibc");
const isOpinit = Boolean(type.startsWith("/opinit"));

Expand Down
3 changes: 2 additions & 1 deletion src/lib/pages/tx-details/components/tx-message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import type { logs } from "@cosmjs/stargate";
import { useState } from "react";

import type { MsgBody } from "lib/services/tx";
import type { Option } from "lib/types";

import { TxMsgDetails } from "./TxMsgDetails";
import { TxMsgExpand } from "./TxMsgExpand";

export interface TxMsgData {
msgBody: MsgBody;
log: logs.Log;
log: Option<logs.Log>;
isSingleMsg?: boolean;
}

Expand Down
379 changes: 379 additions & 0 deletions src/lib/utils/tx/__test__/extractTxLogs.example.ts

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/lib/utils/tx/__test__/extractTxLogs.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { extractTxLogs } from "../extractTxLogs";

import { fromLogs, fromEvents } from "./extractTxLogs.example";
import {
fromLogs,
fromLogsTxFailed,
fromEvents,
fromEventsTxFailed,
} from "./extractTxLogs.example";

describe("extractTxLogs", () => {
test("from logs", () => {
expect(extractTxLogs(fromLogs.txData)).toEqual(fromLogs.result);
});
test("from logs Tx Failed", () => {
expect(extractTxLogs(fromLogsTxFailed.txData)).toEqual(
fromLogsTxFailed.result
);
});
test("from events", () => {
expect(extractTxLogs(fromEvents.txData)).toEqual(fromEvents.result);
});
test("from events Tx Failed", () => {
expect(extractTxLogs(fromEventsTxFailed.txData)).toEqual(
fromEventsTxFailed.result
);
});
});
33 changes: 15 additions & 18 deletions src/lib/utils/tx/extractTxLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@ import type { Event, logs } from "@cosmjs/stargate";
import type { TxResponse } from "lib/services/tx";

export const extractTxLogs = (txData: TxResponse): logs.Log[] => {
const msgLogs = txData.tx.body.messages.map((_, idx) => ({
msg_index: idx,
// Failed Tx - no logs
if (txData.code !== 0) return [];

// pre Cosmos SDK 0.50
if (txData.logs.length > 0) return txData.logs;

// post Cosmos SDK 0.50
const msgLogs = txData.tx.body.messages.map((_, index) => ({
msg_index: index,
log: "",
events: [] as Event[],
}));

if (txData.logs.length > 0)
txData.logs.forEach((log) =>
msgLogs[log.msg_index].events.push(...log.events)
);
else
txData.events.forEach((event) => {
const attribute = event.attributes.find(
(attr) => attr.key === "msg_index"
);
if (attribute) {
const index = Number(attribute.value);
msgLogs[index].events.push(event);
}
});

txData.events.forEach((event) => {
const index = event.attributes.find(
(attr) => attr.key === "msg_index"
)?.value;
if (index) msgLogs[Number(index)].events.push(event);
});
return msgLogs;
};

1 comment on commit dc4089c

@vercel
Copy link

@vercel vercel bot commented on dc4089c Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.