Display raw instruction data as hex in explorer (#12512)
This commit is contained in:
parent
965f653471
commit
f0e02d2588
|
@ -1,18 +1,18 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import bs58 from "bs58";
|
|
||||||
import { TransactionInstruction } from "@solana/web3.js";
|
import { TransactionInstruction } from "@solana/web3.js";
|
||||||
import { Copyable } from "components/common/Copyable";
|
|
||||||
import { Address } from "components/common/Address";
|
import { Address } from "components/common/Address";
|
||||||
|
|
||||||
function displayData(data: string) {
|
function wrap(input: string, length: number): string {
|
||||||
if (data.length > 50) {
|
var result = [];
|
||||||
return `${data.substring(0, 49)}…`;
|
while (input.length) {
|
||||||
|
result.push(input.substr(0, length));
|
||||||
|
input = input.substr(length);
|
||||||
}
|
}
|
||||||
return data;
|
return result.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RawDetails({ ix }: { ix: TransactionInstruction }) {
|
export function RawDetails({ ix }: { ix: TransactionInstruction }) {
|
||||||
const data = bs58.encode(ix.data);
|
const data = wrap(ix.data.toString("hex"), 50);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -40,11 +40,9 @@ export function RawDetails({ ix }: { ix: TransactionInstruction }) {
|
||||||
))}
|
))}
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Instruction Data (Base58)</td>
|
<td>Instruction Data (Hex)</td>
|
||||||
<td className="text-lg-right">
|
<td className="text-lg-right">
|
||||||
<Copyable text={data} right>
|
<pre className="d-inline-block text-left mb-0">{data}</pre>
|
||||||
<code>{displayData(data)}</code>
|
|
||||||
</Copyable>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in New Issue