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

@reflexer-finance/geb-typechain

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reflexer-finance/geb-typechain - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

40

lib/codegen.js

@@ -69,5 +69,24 @@ "use strict";

function codegenForFunctions(fns, abi) {
return lodash_1.values(fns)
// Flatten the overload by adding a number suffix to their name
const flattened = {};
for (let name in fns) {
if (fns[name].length === 1) {
// No overload
flattened[name] = fns[name][0];
}
else {
// Function is overloaded, add a number suffix to the function name for each overload
let i = 1;
for (let overload of fns[name]) {
const overloadName = name + i.toString();
flattened[overloadName] = overload;
flattened[overloadName].name = overloadName;
i++;
}
}
}
// Generate the code
return lodash_1.values(flattened)
.map((fns) => {
return codegenForSingleFunction(fns[0], getABIFragment(fns[0], abi));
return codegenForSingleFunction(fns, getABIFragment(fns, abi));
})

@@ -77,7 +96,16 @@ .join('\n');

exports.codegenForFunctions = codegenForFunctions;
// Given a function declaration, finds the right abi fragment in it. Take into account overload with id suffixes
function getABIFragment(fn, abi) {
for (let fragment of abi) {
if (fragment.name === fn.name &&
fn.inputs.length === fragment.inputs.length &&
fn.inputs.map((input, i) => input.type.originalType === fragment.inputs[i].type)) {
if (!fragment.name) {
continue;
}
// If overload, these are not equal because of the suffix
const isOverloaded = fragment.name.length !== fn.name.length &&
/^-?\d+$/.test(fn.name.slice(fragment.name.length));
if (fn.name === fragment.name ||
(fn.name.startsWith(fragment.name) &&
isOverloaded &&
fn.inputs.length === fragment.inputs.length &&
fn.inputs.map((input, i) => input.type.originalType === fragment.inputs[i].type))) {
return fragment;

@@ -89,3 +117,3 @@ }

function codegenForSingleFunction(fn, abiFragment) {
const isView = fn.stateMutability === 'view';
const isView = fn.stateMutability === 'view' || fn.stateMutability === 'pure';
const inputTypes = types_1.generateInputTypes(fn.inputs, fn.stateMutability);

@@ -92,0 +120,0 @@ const outputType = types_1.generateOutputTypes(fn.outputs);

4

package.json
{
"name": "@reflexer-finance/geb-typechain",
"version": "0.0.5",
"version": "0.0.6",
"description": "",

@@ -19,3 +19,3 @@ "main": "./lib/index.js",

},
"gitHead": "b09e359b83171d077c137e10ebfe7801d3949bde"
"gitHead": "d7cef5d14ffd31e5e413cf81cfb7ccfda0df3f02"
}

@@ -94,5 +94,24 @@ import {

): string {
return values(fns)
// Flatten the overload by adding a number suffix to their name
const flattened: Dictionary<FunctionDeclaration> = {}
for (let name in fns) {
if (fns[name].length === 1) {
// No overload
flattened[name] = fns[name][0]
} else {
// Function is overloaded, add a number suffix to the function name for each overload
let i = 1
for (let overload of fns[name]) {
const overloadName = name + i.toString()
flattened[overloadName] = overload
flattened[overloadName].name = overloadName
i++
}
}
}
// Generate the code
return values(flattened)
.map((fns) => {
return codegenForSingleFunction(fns[0], getABIFragment(fns[0], abi))
return codegenForSingleFunction(fns, getABIFragment(fns, abi))
})

@@ -102,2 +121,3 @@ .join('\n')

// Given a function declaration, finds the right abi fragment in it. Take into account overload with id suffixes
function getABIFragment(

@@ -108,9 +128,19 @@ fn: FunctionDeclaration,

for (let fragment of abi) {
if (!fragment.name) {
continue
}
// If overload, these are not equal because of the suffix
const isOverloaded =
fragment.name.length !== fn.name.length &&
/^-?\d+$/.test(fn.name.slice(fragment.name.length))
if (
fragment.name === fn.name &&
fn.inputs.length === fragment.inputs.length &&
fn.inputs.map(
(input, i) =>
input.type.originalType === fragment.inputs[i].type
)
fn.name === fragment.name ||
(fn.name.startsWith(fragment.name) &&
isOverloaded &&
fn.inputs.length === fragment.inputs.length &&
fn.inputs.map(
(input, i) =>
input.type.originalType === fragment.inputs[i].type
))
) {

@@ -127,3 +157,4 @@ return fragment

): string {
const isView = fn.stateMutability === 'view'
const isView =
fn.stateMutability === 'view' || fn.stateMutability === 'pure'
const inputTypes = generateInputTypes(fn.inputs, fn.stateMutability)

@@ -130,0 +161,0 @@ const outputType = generateOutputTypes(fn.outputs)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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