Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

anchor-idl-converter

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anchor-idl-converter - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

7

package.json
{
"name": "anchor-idl-converter",
"description": "Converter for Anchor IDL, convert your IDL from anchor new version to old version",
"version": "0.0.3",
"version": "0.0.4",
"keywords": [

@@ -46,4 +46,3 @@ "anchor",

"main": "src/index.ts",
"scripts": {
},
"scripts": {},
"devDependencies": {

@@ -59,2 +58,2 @@ "@types/bun": "latest",

}
}
}

@@ -6,2 +6,5 @@ # anchor-idl-converter

> [!WARNING]
> This tools is only hacky solution, and may not work for all cases.
## How to use

@@ -8,0 +11,0 @@ ```bash

@@ -9,3 +9,3 @@ #!/usr/bin/env bun

const program = new Command()
.version('0.0.3')
.version('0.0.4')
.description('converter anchor idl')

@@ -12,0 +12,0 @@

@@ -1,5 +0,3 @@

import fs from 'fs'
import path from 'path'
import { type Root as Type1Root } from './types/anchor_new'
import { type Root as Type2Root } from './types/anchor_old'
import { type Root as AnchorIDLNew } from './types/anchor_new'
import { type Root as AnchorIDLOld } from './types/anchor_old'

@@ -61,9 +59,9 @@ export const convertSnakeCaseToCamelCase = (str: string) => {

}
export function anchorIDLConvertNewToOld(data: any): any {
export function anchorIDLConvertNewToOld(data: AnchorIDLNew): AnchorIDLOld {
return {
version: data.metadata.version,
name: data.metadata.name,
instructions: data.instructions.map((instruction: any) => ({
instructions: data.instructions.map((instruction) => ({
name: convertSnakeCaseToCamelCase(instruction.name),
accounts: instruction.accounts.map((account: any) => ({
accounts: instruction.accounts.map((account) => ({
name: convertSnakeCaseToCamelCase(account.name),

@@ -73,3 +71,3 @@ isMut: account.writable || false,

})),
args: instruction.args.map((arg: any) => ({
args: instruction.args.map((arg) => ({
name: convertSnakeCaseToCamelCase(arg.name),

@@ -79,12 +77,12 @@ type: convertType(arg.type, data),

})),
accounts: data.accounts.map((account: any) => ({
accounts: data.accounts.map((account) => ({
name: account.name,
type: convertType(data.types.find((type: any) => type.name === account.name)?.type, data),
type: convertType(data.types.find((type) => type.name === account.name)?.type, data),
})),
types: data.types.map((type: any) => ({
types: data.types.map((type) => ({
name: type.name,
type: convertType(type.type),
})),
errors: data.instructions.flatMap((instruction: any) =>
instruction.args.filter((arg: any) => arg.type.kind === 'error').map((arg: any) => ({
errors: data.instructions.flatMap((instruction) =>
instruction.args.filter((arg) => arg.type.kind === 'error').map((arg) => ({
code: 0, // Placeholder, as there are no codes in the example.

@@ -99,10 +97,2 @@ name: arg.name,

};
}
// const targetIDL = NokishiftIDL
// const convertedIDL = convertTypes1ToTypes2(targetIDL)
// const convertedIDLPath = path.join(__dirname, 'idl-converted.json')
// fs.writeFileSync(convertedIDLPath, JSON.stringify(convertedIDL, null, 2))
// console.log('convertedIDLPath', convertedIDLPath)
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc