0.4.40 • Published 2 years ago

idl-parser-core v0.4.40

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

IDL Parser

Support converting IDL files to transaction instruction. Useful for smart contract test run, time-saving for writing test case.

Install

yarn add idl-parser-core

Usage

import { ParserProvider } from 'idl-parser-core'

const RPC: 'https://api.devnet.solana.com'

const App = () => {
  return (
    <ParserProvider
      rpc={RPC}
      walletAddress={walletAddress}
      programAddresses={{ provider }}
    >
      <View />
    </ParserProvider>
  )
}

rpc: rpc api url address \ walletAddress: user wallet address \ programAddresses: địa chỉ chương trình smartcontract\ appId: id html element hiển thị modal.

Component

Giao diện mặc định của thư viện idl-parser-core

IDLParserWrapper

import { IDLParserWrapper } from 'idl-parser-core'

<IDLParserWrapper />
  • Giao diện mặc định của thư viện idl-parser-core: upload file idl, form accounts và arguments

TemplateView, InstructionView

import { TemplateView, InstructionView } from 'idl-parser-core'

<TemplateView />

<InstructionView />
  • TemplateView: Giao diện cấu trúc file IDL được tải lên.
  • InstructionView: Giao diện mặc định form accounts và arguments của file IDL được tải lên.

UploadIdl, ViewUploadedIdl

import { UploadIdl, ViewUploadedIdl } from 'idl-parser-core'

<UploadIdl />

<ViewUploadedIdl />
  • UploadIdl: Giao diện mặc định để tải lên file IDL.
  • ViewUploadedIdl: Giao diện mặc định hiển thị file IDL được tải lên._

Hooks

Cung cấp các function để thao tác với dữ liệu, thêm, sửa, xoá với file IDL được tải lên. Lấy thông tin được điền vào từ form accounts, arguments, hoặc dữ liệu file IDL sau khi chuyển đổi.

  • useParser

    • uploadIdl: function tải lên file IDL
    • removeIdl: function xoá file IDL được tải lên
    • parser: dữ liệu của file IDL được tải lên
      const {
        parser: { idl, ixSelected, accountsMetas, argsMetas, remainingAccounts },
      } = useParser()
      • idl: file IDL được tải lên
      • accountsMetas: dữ liệu accounts.
      • argsMetas: dữ liệu argsMetas.
      • ixSelected: instruction đang được chọn.
      • remainingAccounts: dữ liệu remainingAccounts.
    • rpc: địa chỉ rpc blockchain.
    • walletAddress: địa chỉ ví của người dùng.
    • programAddresses: địa chỉ chương trình smartcontract.\ programAddress.idl địa chỉ program được lấy từ file IDL tải lên.\ programAddress.custom địa chỉ program được người dùng thêm, sửa , xoá.\ programAddress.provider địa chỉ program bắt buộc thêm vào khi khởi tạo providerParser để thư viện xác định địa chỉ chương trình mà fileIDL đang tương tác.
      const {
        programAddress: {
          custom: customProgramAddress,
          idl: idlProgramAddress,
          provider: providerProgramAddress,
        },
      } = useParser()
    • setProgramAddress(programAddress: string): function cài địa chỉ cho chương trình IDL. Địa chỉ chương trình sẽ được thêm vào programAddress.custom
      const {
        programAddress: { custom: customProgramAddress },
      } = useParser()
    • setAccountsMeta({ name: string, data: KeypairMeta }): function thêm dữ liệu cho trường accounts. Dữ liệu sẽ được thêm vào parser.accountsMetas.
      const {
        parser: { accountsMetas },
      } = useParser()
    • setArgsMeta({ name: string, val: string }): function thêm dữ liệu cho trường arguments. Dữ liệu sẽ được thêm vào parser.argsMetas.
      const {
        parser: { argsMetas },
      } = useParser()
    • setInstruction(val: string): function chọn instruction để thao tác. Instruction được chọn sẽ thêm vào parser.ixSelected.
      const {
        parser: { ixSelected },
      } = useParser()
    • txInstructions: transaction instruction được chuyển đổi sau khi điền đầy đủ thông tin accounts, argument và remainning accounts nếu có.
      const { txInstructions } = useParser()
    • setTxInstructions: function thêm dữ liệu cho txInstructions.

      const { setTxInstructions } = useParser()
      
      function () {
        ...
        setTxInstructions(instruction)
        ...
      }

Guideline

Upload file idl

  • Button Choose IDL file: select to upload file idl.

IDL instructions

  • Program Address: địa chỉ chương trình idl đang tương tác.
  • File details:
    • File name.
    • Icon : click to remove idl file.
  • Group button instructions: Select instruction wana parse to transaction.
  • Accounts: Bao gồm những địa chỉ account cần để tạo và thực hiện transaction.
  • Arguments: Là những giá trị được truyền vào tương ứng với giá trị được yêu cầu của transaction.

  • Remaining accounts: Là tham số được dùng trong một số transaction đặc biệt như tạo account, deposit .v.v .Có dạng như sau:

      {
        isSigner: boolean,
        isWriter: boolean,
        publicKey: PublicKey
      }

    Bấm nút Add để tạo thêm và bấm nút để xoá remaining account.

Auto complete

Coming soon

Selection

Hỗ trợ người dùng điền nhanh chóng những trường của accounts, arguments và remaining.

  • Wallet Address: địa chỉ ví được cung cấp từ parserProvider
  • New Keypaire: tạo 1 keypair mới.
  • Program Account Data: lấy dữ liệu của account từ địa chỉ account. Ví dụ nhập địa chỉ pool để lấy thông tin của pool.
  • PDA - Token Account: derive địa chỉ token acount từ địa chỉ mint và địa chỉ owner.
  • PDA - Orther: tạo một địa chỉ bằng cách hash 2 chuổi ký tự với nhau.
  • Recents: Tất cả những địa chỉ đã nhập trước đó.
  • System: những địa chỉ chương trình mặc định được cung cấp bởi Solana

Review

Xem lại Transaction được tạo ra khi điền đầy đủ accounts và arguments của instruction.

Project example: https://github.com/DescartesNetwork/idl-parser

0.4.40

2 years ago

0.4.39

2 years ago

0.4.38

2 years ago

0.4.37

2 years ago

0.4.36

2 years ago

0.4.35

2 years ago

0.4.34

2 years ago

0.4.33

2 years ago

0.4.32

2 years ago

0.4.31

2 years ago

0.4.30

2 years ago

0.4.29

2 years ago

0.4.28

2 years ago

0.4.27

2 years ago

0.4.26

2 years ago

0.4.25

2 years ago

0.4.24

2 years ago

0.4.23

2 years ago

0.4.22

2 years ago

0.4.21

2 years ago

0.4.20

2 years ago

0.4.19

2 years ago

0.4.18

2 years ago

0.4.17

2 years ago

0.4.16

2 years ago

0.4.14

2 years ago

0.4.12

2 years ago

0.4.11

2 years ago

0.4.9

2 years ago

0.4.8

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.38

2 years ago

0.3.39

2 years ago