From b33d7cd89302eb35a8cf184eea062c727a06570e Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Sat, 9 May 2020 18:28:58 +0800 Subject: [PATCH] Add support for more system instructions --- explorer/package-lock.json | 11 ++- explorer/package.json | 2 +- .../system/AllocateDetailsCard.tsx | 61 +++++++++++++ .../system/AllocateWithSeedDetailsCard.tsx | 89 +++++++++++++++++++ .../instruction/system/AssignDetailsCard.tsx | 8 +- .../system/AssignWithSeedDetailsCard.tsx | 84 +++++++++++++++++ .../instruction/system/SystemDetailsCard.tsx | 17 +++- 7 files changed, 257 insertions(+), 15 deletions(-) create mode 100644 explorer/src/components/instruction/system/AllocateDetailsCard.tsx create mode 100644 explorer/src/components/instruction/system/AllocateWithSeedDetailsCard.tsx create mode 100644 explorer/src/components/instruction/system/AssignWithSeedDetailsCard.tsx diff --git a/explorer/package-lock.json b/explorer/package-lock.json index 124487781e..9d2236b8a9 100644 --- a/explorer/package-lock.json +++ b/explorer/package-lock.json @@ -1269,9 +1269,8 @@ "integrity": "sha512-DetpxZw1fzPD5xUBrIAoplLChO2VB8DlL5Gg+I1IR9b2wPqYIca2WSUxL5g1vLeR4MsQq1NeWriXAVffV+U1Fw==" }, "@solana/web3.js": { - "version": "0.48.1", - "resolved": "https://registry.npmjs.org/@solana/web3.js/-/web3.js-0.48.1.tgz", - "integrity": "sha512-fzOv8yodlRI8ehjKJPX7Xd0wmswYrzWoHBnf3Anm0FdDaLT5J1riTcE9w6mHijnh97KuIGdD5DQ3J6RX0Sbp4g==", + "version": "github:jstarry/solana-web3.js#93d3d4e6288c99d028610254fb525f40b18b9dec", + "from": "github:jstarry/solana-web3.js#add-system-ixs", "requires": { "@babel/runtime": "^7.3.1", "bn.js": "^5.0.0", @@ -1627,9 +1626,9 @@ "integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==" }, "@types/express-serve-static-core": { - "version": "4.17.6", - "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.6.tgz", - "integrity": "sha512-U2oynuRIB17GIbEdvjFrrEACOy7GQkzsX7bPEBz1H41vZYEU4j0fLL97sawmHDwHUXpUQDBMHIyM9vejqP9o1A==", + "version": "4.17.7", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.7.tgz", + "integrity": "sha512-EMgTj/DF9qpgLXyc+Btimg+XoH7A2liE8uKul8qSmMTHCeNYzydDKFdsJskDvw42UsesCnhO63dO0Grbj8J4Dw==", "requires": { "@types/node": "*", "@types/qs": "*", diff --git a/explorer/package.json b/explorer/package.json index e2423e90fe..116b9a2fdf 100644 --- a/explorer/package.json +++ b/explorer/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { - "@solana/web3.js": "^0.48.1", + "@solana/web3.js": "github:jstarry/solana-web3.js#add-system-ixs", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", diff --git a/explorer/src/components/instruction/system/AllocateDetailsCard.tsx b/explorer/src/components/instruction/system/AllocateDetailsCard.tsx new file mode 100644 index 0000000000..55fd133992 --- /dev/null +++ b/explorer/src/components/instruction/system/AllocateDetailsCard.tsx @@ -0,0 +1,61 @@ +import React from "react"; +import { + TransactionInstruction, + SystemProgram, + SignatureResult, + SystemInstruction +} from "@solana/web3.js"; +import { displayAddress } from "utils/tx"; +import { InstructionCard } from "../InstructionCard"; +import Copyable from "components/Copyable"; +import { UnknownDetailsCard } from "../UnknownDetailsCard"; + +export function AllocateDetailsCard(props: { + ix: TransactionInstruction; + index: number; + result: SignatureResult; +}) { + const { ix, index, result } = props; + + let params; + try { + params = SystemInstruction.decodeAllocate(ix); + } catch (err) { + console.error(err); + return ; + } + + const accountKey = params.accountPubkey.toBase58(); + + return ( + + + Program + + + {displayAddress(SystemProgram.programId)} + + + + + + Account Address + + + {accountKey} + + + + + + Allocated Space (Bytes) + {params.space} + + + ); +} diff --git a/explorer/src/components/instruction/system/AllocateWithSeedDetailsCard.tsx b/explorer/src/components/instruction/system/AllocateWithSeedDetailsCard.tsx new file mode 100644 index 0000000000..644690ad68 --- /dev/null +++ b/explorer/src/components/instruction/system/AllocateWithSeedDetailsCard.tsx @@ -0,0 +1,89 @@ +import React from "react"; +import { + TransactionInstruction, + SystemProgram, + SignatureResult, + SystemInstruction +} from "@solana/web3.js"; +import { displayAddress } from "utils/tx"; +import { InstructionCard } from "../InstructionCard"; +import Copyable from "components/Copyable"; +import { UnknownDetailsCard } from "../UnknownDetailsCard"; + +export function AllocateWithSeedDetailsCard(props: { + ix: TransactionInstruction; + index: number; + result: SignatureResult; +}) { + const { ix, index, result } = props; + + let params; + try { + params = SystemInstruction.decodeAllocateWithSeed(ix); + } catch (err) { + console.error(err); + return ; + } + + const accountKey = params.accountPubkey.toBase58(); + const baseKey = params.basePubkey.toBase58(); + + return ( + + + Program + + + {displayAddress(SystemProgram.programId)} + + + + + + Account Address + + + {accountKey} + + + + + + Base Address + + + {baseKey} + + + + + + Seed + + + {params.seed} + + + + + + Allocated Space (Bytes) + {params.space} + + + + Assigned Owner + + + {displayAddress(params.programId)} + + + + + ); +} diff --git a/explorer/src/components/instruction/system/AssignDetailsCard.tsx b/explorer/src/components/instruction/system/AssignDetailsCard.tsx index 939872cefd..6a2a1c94f3 100644 --- a/explorer/src/components/instruction/system/AssignDetailsCard.tsx +++ b/explorer/src/components/instruction/system/AssignDetailsCard.tsx @@ -25,7 +25,7 @@ export function AssignDetailsCard(props: { return ; } - const from = params.fromPubkey.toBase58(); + const accountKey = params.accountPubkey.toBase58(); return ( - From Address + Account Address - - {from} + + {accountKey} diff --git a/explorer/src/components/instruction/system/AssignWithSeedDetailsCard.tsx b/explorer/src/components/instruction/system/AssignWithSeedDetailsCard.tsx new file mode 100644 index 0000000000..e98f639fc8 --- /dev/null +++ b/explorer/src/components/instruction/system/AssignWithSeedDetailsCard.tsx @@ -0,0 +1,84 @@ +import React from "react"; +import { + TransactionInstruction, + SystemProgram, + SignatureResult, + SystemInstruction +} from "@solana/web3.js"; +import { displayAddress } from "utils/tx"; +import { InstructionCard } from "../InstructionCard"; +import Copyable from "components/Copyable"; +import { UnknownDetailsCard } from "../UnknownDetailsCard"; + +export function AssignWithSeedDetailsCard(props: { + ix: TransactionInstruction; + index: number; + result: SignatureResult; +}) { + const { ix, index, result } = props; + + let params; + try { + params = SystemInstruction.decodeAssignWithSeed(ix); + } catch (err) { + console.error(err); + return ; + } + + const accountKey = params.accountPubkey.toBase58(); + const baseKey = params.basePubkey.toBase58(); + + return ( + + + Program + + + {displayAddress(SystemProgram.programId)} + + + + + + Account Address + + + {accountKey} + + + + + + Base Address + + + {baseKey} + + + + + + Seed + + + {params.seed} + + + + + + Assigned Owner + + + {displayAddress(params.programId)} + + + + + ); +} diff --git a/explorer/src/components/instruction/system/SystemDetailsCard.tsx b/explorer/src/components/instruction/system/SystemDetailsCard.tsx index 16feb8702b..34138772e0 100644 --- a/explorer/src/components/instruction/system/SystemDetailsCard.tsx +++ b/explorer/src/components/instruction/system/SystemDetailsCard.tsx @@ -7,7 +7,10 @@ import { import { UnknownDetailsCard } from "../UnknownDetailsCard"; import { TransferDetailsCard } from "./TransferDetailsCard"; +import { AllocateDetailsCard } from "./AllocateDetailsCard"; +import { AllocateWithSeedDetailsCard } from "./AllocateWithSeedDetailsCard"; import { AssignDetailsCard } from "./AssignDetailsCard"; +import { AssignWithSeedDetailsCard } from "./AssignWithSeedDetailsCard"; import { CreateDetailsCard } from "./CreateDetailsCard"; import { CreateWithSeedDetailsCard } from "./CreateWithSeedDetailsCard"; import { NonceInitializeDetailsCard } from "./NonceInitializeDetailsCard"; @@ -33,12 +36,18 @@ export function SystemDetailsCard(props: DetailsProps) { switch (systemInstructionType) { case "Create": return ; - case "Assign": - return ; - case "Transfer": - return ; case "CreateWithSeed": return ; + case "Allocate": + return ; + case "AllocateWithSeed": + return ; + case "Assign": + return ; + case "AssignWithSeed": + return ; + case "Transfer": + return ; case "AdvanceNonceAccount": return ; case "WithdrawNonceAccount":