-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ron parser utils * Use ron parser utils * Better showcase with filters * Tweak parser for details * Account for simulations * Avoid sm.process_msg for wasm * Add isQuery to Operation * Draw dashed for queries * Avoid duplicate arrows for Bank * Add activation boxes for queries * Render spans for empty mermaid charts
- Loading branch information
Showing
8 changed files
with
282 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Span } from "@/types/txs"; | ||
import SpanDetails from "./span-details"; | ||
|
||
type SpansDetailsProps = { | ||
spans: readonly Span[]; | ||
}; | ||
|
||
export default function SpansDetails({ spans }: SpansDetailsProps) { | ||
return spans.map((span) => ( | ||
<> | ||
{spans.length > 1 ? ( | ||
<h2> | ||
Operation <span className="font-bold">{span.operationName}</span>{" "} | ||
<span className="font-mono">{span.spanId}</span> | ||
</h2> | ||
) : null} | ||
<SpanDetails key={span.spanId} span={span} /> | ||
</> | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
import { Span } from "@/types/txs"; | ||
|
||
type Operation = { | ||
label: string; | ||
isQuery: boolean; | ||
sender: string; | ||
recipient: string; | ||
traceId: string; | ||
spanId: string; | ||
}; | ||
|
||
export const getActorsFromOperations = ( | ||
operations: readonly Operation[], | ||
): readonly string[] => | ||
Array.from( | ||
new Set( | ||
operations.flatMap((operation) => [ | ||
operation.sender, | ||
operation.recipient, | ||
]), | ||
), | ||
); | ||
|
||
export const getOperationsFromSpans = ( | ||
spans: Readonly<Array<Span>>, | ||
): readonly Operation[] => | ||
spans | ||
.map((span) => { | ||
const txRon = | ||
span.tags.get("request") || span.tags.get("msg") || span.tags.get("tx"); | ||
if (!txRon) { | ||
return null; | ||
} | ||
|
||
switch (true) { | ||
//NOTE - Avoids showing both execute_tx and sm.process_msg for bank queries | ||
case txRon.includes("Bank(") && | ||
span.operationName === "sm.process_msg": { | ||
return null; | ||
} | ||
case txRon.includes("Bank(Send"): { | ||
return parseActorFromBankSendRon(txRon, span); | ||
} | ||
//NOTE - Avoids showing both execute_tx and sm.process_msg for wasm queries | ||
case txRon.includes("Wasm(") && | ||
span.operationName === "sm.process_msg": { | ||
return null; | ||
} | ||
case txRon.includes("Wasm(StoreCode"): { | ||
return parseActorFromWasmStoreCodeRon(txRon, span); | ||
} | ||
case txRon.includes("Wasm(Instantiate"): { | ||
return parseActorFromWasmInstantiateRon(txRon, span); | ||
} | ||
case txRon.includes("Wasm(Migrate"): { | ||
return parseActorFromWasmMigrateRon(txRon, span); | ||
} | ||
case txRon.includes("Wasm(Execute"): { | ||
return parseActorFromWasmExecuteRon(txRon, span); | ||
} | ||
case txRon.includes("Wasm(UpdateAdmin"): { | ||
return parseActorFromWasmUpdateAdminRon(txRon, span); | ||
} | ||
default: { | ||
return null; | ||
} | ||
} | ||
}) | ||
.filter((operation): operation is Operation => !!operation); | ||
|
||
const parseActorFromBankSendRon = ( | ||
bankSendRon: string, | ||
{ traceId, spanId }: Span, | ||
): Operation | null => { | ||
const sender = bankSendRon.match(/sender: (\w+)/)?.[1]; | ||
const recipient = bankSendRon.match(/recipient: (\w+)/)?.[1]; | ||
|
||
if (!sender || !recipient) { | ||
return null; | ||
} | ||
|
||
const isSimulation = bankSendRon.includes("Simulate("); | ||
|
||
return { | ||
label: isSimulation ? "๐ป๐ฆ Send" : "๐ฆ Send", | ||
isQuery: isSimulation, | ||
sender, | ||
recipient, | ||
traceId, | ||
spanId, | ||
}; | ||
}; | ||
|
||
const parseActorFromWasmStoreCodeRon = ( | ||
wasmStoreCodeRon: string, | ||
{ traceId, spanId }: Span, | ||
): Operation | null => { | ||
const sender = wasmStoreCodeRon.match(/sender: (\w+)/)?.[1]; | ||
|
||
if (!sender) { | ||
return null; | ||
} | ||
|
||
const isSimulation = wasmStoreCodeRon.includes("Simulate("); | ||
|
||
return { | ||
label: isSimulation ? "๐ป๐ธ Store code" : "๐ธ Store code", | ||
isQuery: isSimulation, | ||
sender, | ||
recipient: sender, | ||
traceId, | ||
spanId, | ||
}; | ||
}; | ||
|
||
const parseActorFromWasmInstantiateRon = ( | ||
wasmInstantiateRon: string, | ||
{ traceId, spanId }: Span, | ||
): Operation | null => { | ||
const sender = wasmInstantiateRon.match(/sender: (\w+)/)?.[1]; | ||
|
||
if (!sender) { | ||
return null; | ||
} | ||
|
||
const isSimulation = wasmInstantiateRon.includes("Simulate("); | ||
|
||
return { | ||
label: isSimulation ? "๐ป๐ธ Instantiate" : "๐ธ Instantiate", | ||
isQuery: isSimulation, | ||
sender, | ||
recipient: sender, | ||
traceId, | ||
spanId, | ||
}; | ||
}; | ||
|
||
const parseActorFromWasmMigrateRon = ( | ||
wasmMigrateRon: string, | ||
{ traceId, spanId }: Span, | ||
): Operation | null => { | ||
const sender = wasmMigrateRon.match(/sender: (\w+)/)?.[1]; | ||
|
||
if (!sender) { | ||
return null; | ||
} | ||
|
||
const isSimulation = wasmMigrateRon.includes("Simulate("); | ||
|
||
return { | ||
label: isSimulation ? "๐ป๐ธ Migrate" : "๐ธ Migrate", | ||
isQuery: isSimulation, | ||
sender, | ||
recipient: sender, | ||
traceId, | ||
spanId, | ||
}; | ||
}; | ||
|
||
const parseActorFromWasmExecuteRon = ( | ||
wasmExecuteRon: string, | ||
{ traceId, spanId }: Span, | ||
): Operation | null => { | ||
const sender = wasmExecuteRon.match(/sender: (\w+)/)?.[1]; | ||
const contractAddr = wasmExecuteRon.match(/contract_addr: (\w+)/)?.[1]; | ||
|
||
if (!sender || !contractAddr) { | ||
return null; | ||
} | ||
|
||
const isSimulation = wasmExecuteRon.includes("Simulate("); | ||
|
||
return { | ||
label: isSimulation ? "๐ป๐ธ Execute" : "๐ธ Execute", | ||
isQuery: isSimulation, | ||
sender, | ||
recipient: contractAddr, | ||
traceId, | ||
spanId, | ||
}; | ||
}; | ||
|
||
const parseActorFromWasmUpdateAdminRon = ( | ||
wasmUpdateAdminRon: string, | ||
{ traceId, spanId }: Span, | ||
): Operation | null => { | ||
const sender = wasmUpdateAdminRon.match(/sender: (\w+)/)?.[1]; | ||
const contractAddr = wasmUpdateAdminRon.match(/contract_addr: (\w+)/)?.[1]; | ||
|
||
if (!sender || !contractAddr) { | ||
return null; | ||
} | ||
|
||
const isSimulation = wasmUpdateAdminRon.includes("Simulate("); | ||
|
||
return { | ||
label: isSimulation ? "๐ป๐ธ Update admin" : "๐ธ Update admin", | ||
isQuery: isSimulation, | ||
sender, | ||
recipient: contractAddr, | ||
traceId, | ||
spanId, | ||
}; | ||
}; |
Oops, something went wrong.