mirror of
https://github.com/wharfkit/contract.git
synced 2026-07-21 17:43:29 +00:00
Removed codegen logic (#55)
* chore: removed codegen logic * Removed a few more things --------- Co-authored-by: Aaron Cox <aaron@greymass.com>
This commit is contained in:
@@ -51,10 +51,6 @@ publish: | distclean node_modules
|
||||
docs: build/docs
|
||||
@open build/docs/index.html
|
||||
|
||||
.PHONY: generate
|
||||
generate: lib
|
||||
node -r esm scripts/codegen-cli.js $(contract)
|
||||
|
||||
build/docs: $(SRC_FILES) node_modules
|
||||
@${BIN}/typedoc --out build/docs \
|
||||
--excludeInternal --excludePrivate --excludeProtected \
|
||||
|
||||
@@ -9,7 +9,6 @@ Features:
|
||||
- Create action data by accessing actions directly through the `.action` method of a `Contract`
|
||||
- Retrieve Ricardian Contracts for specific actions through the `.ricardian` method of a `Contract`
|
||||
- Cache and optimize ABI call patterns automatically in your application.
|
||||
- Generate frontend code based on a smart contracts ABI.
|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
"scripts": {
|
||||
"prepare": "make"
|
||||
},
|
||||
"bin": {
|
||||
"wharf-generate": "./scripts/codegen-cli.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@wharfkit/abicache": "^1.1.1",
|
||||
"@wharfkit/antelope": "^0.7.3",
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const {APIClient} = require('@wharfkit/session')
|
||||
const fs = require('fs')
|
||||
const {fetch} = require('node-fetch')
|
||||
|
||||
const {codegen, ContractKit} = require('../lib/contract.js')
|
||||
|
||||
const client = new APIClient({
|
||||
url: process.env.ANTELOPE_NODE_URL || 'https://eos.greymass.com',
|
||||
fetch,
|
||||
})
|
||||
|
||||
async function codegenCli() {
|
||||
// Check if the contractName argument is provided
|
||||
if (process.argv.length < 3) {
|
||||
console.error('Usage: wharf-generate {contractName}')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// Get the contract name from the command line arguments
|
||||
const contractName = process.argv[2]
|
||||
|
||||
log(`Fetching ABI for ${contractName}...`)
|
||||
|
||||
const contractKit = new ContractKit({
|
||||
client,
|
||||
})
|
||||
const contract = await contractKit.load(contractName)
|
||||
|
||||
log(`Generating Contract helper for ${contractName}...`)
|
||||
|
||||
const generatedCode = await codegen(contractName, contract.abi)
|
||||
|
||||
log(`Generated Contract helper class for ${contractName}...`)
|
||||
|
||||
// Check if --file is present in the command line arguments
|
||||
const fileFlagIndex = process.argv.indexOf('--file')
|
||||
if (fileFlagIndex !== -1 && process.argv[fileFlagIndex + 1]) {
|
||||
const contractFilePath = process.argv[fileFlagIndex + 1]
|
||||
|
||||
fs.writeFileSync(contractFilePath, generatedCode)
|
||||
|
||||
log(`Generated Contract helper for ${contractName} saved to ${contractFilePath}`)
|
||||
} else {
|
||||
log(`Generated Contract helper class:`)
|
||||
log(generatedCode)
|
||||
}
|
||||
}
|
||||
|
||||
function log(message) {
|
||||
process.stderr.write(`${message}\n`)
|
||||
}
|
||||
|
||||
codegenCli()
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
import * as prettier from 'prettier'
|
||||
import * as ts from 'typescript'
|
||||
import {generateContractClass} from './codegen/contract'
|
||||
import {generateImportStatement, getCoreImports} from './codegen/helpers'
|
||||
import {generateActionNamesInterface, generateActionsNamespace} from './codegen/interfaces'
|
||||
import {generateTableMap} from './codegen/maps'
|
||||
import {generateNamespace, generateNamespaceName} from './codegen/namespace'
|
||||
import {generateStructClasses} from './codegen/structs'
|
||||
import {abiToBlob} from './utils'
|
||||
|
||||
const printer = ts.createPrinter()
|
||||
|
||||
export async function codegen(contractName, abi) {
|
||||
try {
|
||||
const namespaceName = generateNamespaceName(contractName)
|
||||
|
||||
const importContractStatement = generateImportStatement(
|
||||
['ActionOptions', 'Contract as BaseContract', 'ContractArgs', 'PartialBy'],
|
||||
'@wharfkit/contract'
|
||||
)
|
||||
|
||||
const allAntelopeImports = [
|
||||
'ABI',
|
||||
'Action',
|
||||
'Blob',
|
||||
'Struct',
|
||||
'Name',
|
||||
...getCoreImports(abi),
|
||||
]
|
||||
const antelopeImports = allAntelopeImports.filter(
|
||||
(item, index) => allAntelopeImports.indexOf(item) === index
|
||||
)
|
||||
|
||||
antelopeImports.sort()
|
||||
|
||||
const importCoreStatement = generateImportStatement(antelopeImports, '@wharfkit/antelope')
|
||||
|
||||
const {classDeclaration} = await generateContractClass(contractName, abi)
|
||||
|
||||
const actionNamesInterface = generateActionNamesInterface(abi)
|
||||
|
||||
const actionsNamespace = generateActionsNamespace(abi)
|
||||
|
||||
// Iterate through structs and create struct classes with fields
|
||||
const structDeclarations = generateStructClasses(abi)
|
||||
|
||||
// Encode the ABI as a binary hex string
|
||||
const abiBlob = abiToBlob(abi)
|
||||
|
||||
// Generate `abiBlob` field
|
||||
const abiBlobField = ts.factory.createVariableStatement(
|
||||
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
||||
ts.factory.createVariableDeclarationList(
|
||||
[
|
||||
ts.factory.createVariableDeclaration(
|
||||
'abiBlob',
|
||||
undefined,
|
||||
undefined,
|
||||
ts.factory.createCallExpression(
|
||||
ts.factory.createPropertyAccessExpression(
|
||||
ts.factory.createIdentifier('Blob'),
|
||||
ts.factory.createIdentifier('from')
|
||||
),
|
||||
undefined,
|
||||
[ts.factory.createStringLiteral(String(abiBlob))]
|
||||
)
|
||||
),
|
||||
],
|
||||
ts.NodeFlags.Const
|
||||
)
|
||||
)
|
||||
|
||||
// Generate `abiBlob` field
|
||||
const abiField = ts.factory.createVariableStatement(
|
||||
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
||||
ts.factory.createVariableDeclarationList(
|
||||
[
|
||||
ts.factory.createVariableDeclaration(
|
||||
'abi',
|
||||
undefined,
|
||||
undefined,
|
||||
ts.factory.createCallExpression(
|
||||
ts.factory.createPropertyAccessExpression(
|
||||
ts.factory.createIdentifier('ABI'),
|
||||
ts.factory.createIdentifier('from')
|
||||
),
|
||||
undefined,
|
||||
[ts.factory.createIdentifier('abiBlob')]
|
||||
)
|
||||
),
|
||||
],
|
||||
ts.NodeFlags.Const
|
||||
)
|
||||
)
|
||||
|
||||
const tableMap = generateTableMap(abi)
|
||||
|
||||
const exportStatement = ts.factory.createExportAssignment(
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
ts.factory.createIdentifier(namespaceName)
|
||||
)
|
||||
|
||||
// Generate types namespace
|
||||
const namespaceDeclaration = generateNamespace(namespaceName, [
|
||||
abiBlobField,
|
||||
abiField,
|
||||
classDeclaration,
|
||||
actionNamesInterface,
|
||||
actionsNamespace,
|
||||
generateNamespace('Types', structDeclarations),
|
||||
tableMap,
|
||||
])
|
||||
|
||||
const sourceFile = ts.factory.createSourceFile(
|
||||
[importContractStatement, importCoreStatement, namespaceDeclaration, exportStatement],
|
||||
ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
|
||||
ts.NodeFlags.None
|
||||
)
|
||||
|
||||
const options = await prettier.resolveConfig(process.cwd())
|
||||
return prettier.format(printer.printFile(sourceFile), options)
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`An error occurred while generating the contract code: ${e}`)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
import {ABI} from '@wharfkit/antelope'
|
||||
import * as ts from 'typescript'
|
||||
|
||||
import {generateClassDeclaration} from './helpers'
|
||||
|
||||
export async function generateContractClass(contractName: string, abi: ABI.Def) {
|
||||
// Prepare the member fields of the class
|
||||
const classMembers: ts.ClassElement[] = []
|
||||
|
||||
// Generate the `constructor` member
|
||||
const constructorParams: ts.ParameterDeclaration[] = [
|
||||
ts.factory.createParameterDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'args',
|
||||
undefined,
|
||||
ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('PartialBy'), [
|
||||
ts.factory.createTypeReferenceNode(
|
||||
ts.factory.createIdentifier('ContractArgs'),
|
||||
undefined
|
||||
),
|
||||
ts.factory.createUnionTypeNode([
|
||||
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral('abi')),
|
||||
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral('account')),
|
||||
]),
|
||||
]),
|
||||
undefined
|
||||
),
|
||||
]
|
||||
|
||||
const constructorBody = ts.factory.createBlock(
|
||||
[generateConstructorFunction(contractName)],
|
||||
true
|
||||
)
|
||||
|
||||
const constructorMember = ts.factory.createConstructorDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
constructorParams,
|
||||
constructorBody
|
||||
)
|
||||
|
||||
classMembers.push(constructorMember)
|
||||
|
||||
if (abi.actions.length) {
|
||||
const actionMethod = generateActionMethod(abi)
|
||||
|
||||
classMembers.push(actionMethod)
|
||||
}
|
||||
|
||||
if (abi.tables.length) {
|
||||
const tableMethod = generateTableMethod(abi)
|
||||
|
||||
classMembers.push(tableMethod)
|
||||
}
|
||||
|
||||
// Construct class declaration
|
||||
const classDeclaration = generateClassDeclaration('Contract', classMembers, {
|
||||
parent: 'BaseContract',
|
||||
export: true,
|
||||
})
|
||||
|
||||
return {classDeclaration}
|
||||
}
|
||||
|
||||
function generateConstructorFunction(contractName): ts.ExpressionStatement {
|
||||
return ts.factory.createExpressionStatement(
|
||||
ts.factory.createCallExpression(ts.factory.createSuper(), undefined, [
|
||||
ts.factory.createObjectLiteralExpression(
|
||||
[
|
||||
ts.factory.createPropertyAssignment(
|
||||
'client',
|
||||
ts.factory.createPropertyAccessExpression(
|
||||
ts.factory.createIdentifier('args'),
|
||||
'client'
|
||||
)
|
||||
),
|
||||
ts.factory.createPropertyAssignment('abi', ts.factory.createIdentifier('abi')),
|
||||
ts.factory.createPropertyAssignment(
|
||||
'account',
|
||||
ts.factory.createCallExpression(
|
||||
ts.factory.createPropertyAccessExpression(
|
||||
ts.factory.createIdentifier('Name'),
|
||||
'from'
|
||||
),
|
||||
undefined,
|
||||
[ts.factory.createStringLiteral(contractName)]
|
||||
)
|
||||
),
|
||||
],
|
||||
true
|
||||
),
|
||||
])
|
||||
)
|
||||
}
|
||||
|
||||
function generateActionMethod(abi: ABI.Def): ts.MethodDeclaration {
|
||||
const typeParameter = ts.factory.createTypeParameterDeclaration(
|
||||
'T',
|
||||
ts.factory.createUnionTypeNode(
|
||||
abi.actions.map((action) =>
|
||||
ts.factory.createLiteralTypeNode(
|
||||
ts.factory.createStringLiteral(String(action.name))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
// 3. Create the function parameters.
|
||||
const nameParameter = ts.factory.createParameterDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'name',
|
||||
undefined,
|
||||
ts.factory.createTypeReferenceNode('T'),
|
||||
undefined
|
||||
)
|
||||
|
||||
const dataParameter = ts.factory.createParameterDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'data',
|
||||
undefined,
|
||||
ts.factory.createTypeReferenceNode('ActionNameParams[T]'),
|
||||
undefined
|
||||
)
|
||||
|
||||
const optionsParameter = ts.factory.createParameterDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'options',
|
||||
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
||||
ts.factory.createTypeReferenceNode('ActionOptions'),
|
||||
undefined
|
||||
)
|
||||
|
||||
// 4. Generate the function body.
|
||||
const methodBody = ts.factory.createBlock(
|
||||
[
|
||||
ts.factory.createReturnStatement(
|
||||
ts.factory.createCallExpression(
|
||||
ts.factory.createPropertyAccessExpression(
|
||||
ts.factory.createSuper(),
|
||||
ts.factory.createIdentifier('action')
|
||||
),
|
||||
undefined,
|
||||
[
|
||||
ts.factory.createIdentifier('name'),
|
||||
ts.factory.createIdentifier('data'),
|
||||
ts.factory.createIdentifier('options'),
|
||||
]
|
||||
)
|
||||
),
|
||||
],
|
||||
true
|
||||
)
|
||||
|
||||
return ts.factory.createMethodDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'action',
|
||||
undefined,
|
||||
[typeParameter],
|
||||
[nameParameter, dataParameter, optionsParameter],
|
||||
ts.factory.createTypeReferenceNode('Action'),
|
||||
methodBody
|
||||
)
|
||||
}
|
||||
|
||||
function generateTableMethod(abi: ABI.Def): ts.MethodDeclaration {
|
||||
const typeParameter = ts.factory.createTypeParameterDeclaration(
|
||||
'T',
|
||||
ts.factory.createUnionTypeNode(
|
||||
abi.tables.map((table) =>
|
||||
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(String(table.name)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
// 3. Create the function parameters.
|
||||
const nameParameter = ts.factory.createParameterDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'name',
|
||||
undefined,
|
||||
ts.factory.createTypeReferenceNode('T'),
|
||||
undefined
|
||||
)
|
||||
|
||||
const scopeParameter = ts.factory.createParameterDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'scope',
|
||||
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
||||
ts.factory.createTypeReferenceNode('NameType'),
|
||||
undefined
|
||||
)
|
||||
|
||||
// 4. Generate the function body.
|
||||
const methodBody = ts.factory.createBlock(
|
||||
[
|
||||
ts.factory.createReturnStatement(
|
||||
ts.factory.createCallExpression(
|
||||
ts.factory.createPropertyAccessExpression(
|
||||
ts.factory.createSuper(),
|
||||
ts.factory.createIdentifier('table')
|
||||
),
|
||||
undefined,
|
||||
[
|
||||
ts.factory.createIdentifier('name'),
|
||||
ts.factory.createIdentifier('scope'),
|
||||
ts.factory.createIdentifier('TableMap[name]'),
|
||||
]
|
||||
)
|
||||
),
|
||||
],
|
||||
true
|
||||
)
|
||||
|
||||
return ts.factory.createMethodDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'table',
|
||||
undefined,
|
||||
[typeParameter],
|
||||
[nameParameter, scopeParameter],
|
||||
undefined,
|
||||
methodBody
|
||||
)
|
||||
}
|
||||
@@ -1,242 +0,0 @@
|
||||
import * as Antelope from '@wharfkit/antelope'
|
||||
import {ABI} from '@wharfkit/antelope'
|
||||
import * as ts from 'typescript'
|
||||
|
||||
import {capitalize} from '../utils'
|
||||
|
||||
const ANTELOPE_CLASSES: string[] = []
|
||||
Object.keys(Antelope).map((key) => {
|
||||
if (Antelope[key].abiName) {
|
||||
ANTELOPE_CLASSES.push(key)
|
||||
}
|
||||
})
|
||||
|
||||
export const ANTELOPE_CLASS_MAPPINGS = {
|
||||
block_timestamp_type: 'BlockTimestamp',
|
||||
}
|
||||
|
||||
export function getCoreImports(abi: ABI.Def) {
|
||||
const coreImports: string[] = []
|
||||
for (const struct of abi.structs) {
|
||||
for (const field of struct.fields) {
|
||||
const coreClass = findCoreClass(field.type)
|
||||
|
||||
if (coreClass) {
|
||||
coreImports.push(coreClass)
|
||||
}
|
||||
|
||||
const isAction = abi.actions.find((action) => action.type === struct.name)
|
||||
|
||||
if (!isAction) {
|
||||
continue
|
||||
}
|
||||
|
||||
const coreType = findCoreType(field.type)
|
||||
|
||||
if (coreType) {
|
||||
coreImports.push(coreType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return coreImports.filter((value, index, self) => self.indexOf(value) === index)
|
||||
}
|
||||
|
||||
export function generateClassDeclaration(
|
||||
name: string,
|
||||
members: ts.ClassElement[],
|
||||
options: {parent?: string; export?: boolean; decorator?: ts.Decorator} = {}
|
||||
) {
|
||||
const heritageClauses: ts.HeritageClause[] = []
|
||||
if (options.parent) {
|
||||
heritageClauses.push(
|
||||
ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
|
||||
ts.factory.createExpressionWithTypeArguments(
|
||||
ts.factory.createIdentifier(options.parent),
|
||||
undefined
|
||||
),
|
||||
])
|
||||
)
|
||||
}
|
||||
const modifiers: ts.ModifierLike[] = []
|
||||
if (options.export === true) {
|
||||
modifiers.push(ts.factory.createToken(ts.SyntaxKind.ExportKeyword))
|
||||
}
|
||||
if (options.decorator) {
|
||||
modifiers.push(options.decorator)
|
||||
}
|
||||
const classDeclaration = ts.factory.createClassDeclaration(
|
||||
modifiers,
|
||||
ts.factory.createIdentifier(name),
|
||||
undefined, // type parameters
|
||||
heritageClauses,
|
||||
members
|
||||
)
|
||||
return classDeclaration
|
||||
}
|
||||
|
||||
export function generateImportStatement(classes, path): ts.ImportDeclaration {
|
||||
return ts.factory.createImportDeclaration(
|
||||
undefined, // modifiers
|
||||
ts.factory.createImportClause(
|
||||
false, // isTypeOnly
|
||||
undefined, // name
|
||||
ts.factory.createNamedImports(
|
||||
classes.map((className) =>
|
||||
ts.factory.createImportSpecifier(
|
||||
false,
|
||||
undefined, // propertyName
|
||||
ts.factory.createIdentifier(className) // name
|
||||
)
|
||||
)
|
||||
) // namedBindings
|
||||
),
|
||||
ts.factory.createStringLiteral(path) // moduleSpecifier
|
||||
)
|
||||
}
|
||||
|
||||
export function generateInterface(
|
||||
interfaceName: string,
|
||||
isExport = false,
|
||||
members: ts.TypeElement[]
|
||||
): ts.InterfaceDeclaration {
|
||||
const modifiers = isExport ? [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)] : []
|
||||
|
||||
return ts.factory.createInterfaceDeclaration(
|
||||
modifiers,
|
||||
ts.factory.createIdentifier(interfaceName),
|
||||
undefined, // typeParameters
|
||||
[], // heritageClauses
|
||||
members
|
||||
)
|
||||
}
|
||||
|
||||
export function findCoreClass(type: string): string | undefined {
|
||||
if (ANTELOPE_CLASS_MAPPINGS[type]) {
|
||||
return ANTELOPE_CLASS_MAPPINGS[type]
|
||||
}
|
||||
|
||||
const parsedType = parseType(type).split('_').join('')
|
||||
|
||||
return (
|
||||
ANTELOPE_CLASSES.find((antelopeClass) => parsedType === antelopeClass.toLowerCase()) ||
|
||||
ANTELOPE_CLASSES.find(
|
||||
(antelopeClass) => parsedType.replace(/[0-9]/g, '') === antelopeClass.toLowerCase()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export function findCoreType(type: string): string | undefined {
|
||||
const coreType = findCoreClass(type)
|
||||
|
||||
if (coreType) {
|
||||
return `${coreType}Type`
|
||||
}
|
||||
}
|
||||
|
||||
export function findInternalType(type: string, typeNamespace: string | null, abi: ABI.Def): string {
|
||||
let {type: typeString} = extractDecorator(type)
|
||||
|
||||
typeString = parseType(typeString)
|
||||
|
||||
const relevantAbitype = findAbiType(typeString, abi)
|
||||
|
||||
if (relevantAbitype) {
|
||||
typeString = relevantAbitype
|
||||
}
|
||||
|
||||
return formatInternalType(typeString, typeNamespace, abi)
|
||||
}
|
||||
|
||||
function formatInternalType(typeString: string, namespace: string | null, abi: ABI.Def): string {
|
||||
const structNames = abi.structs.map((struct) => struct.name.toLowerCase())
|
||||
|
||||
if (structNames.includes(typeString.toLowerCase())) {
|
||||
return `${namespace ? `${namespace}` : ''}${generateStructClassName(typeString)}`
|
||||
} else {
|
||||
return findCoreClass(typeString) || capitalize(typeString)
|
||||
}
|
||||
}
|
||||
|
||||
export function generateStructClassName(name) {
|
||||
return name
|
||||
.split('_')
|
||||
.map((word) => capitalize(word))
|
||||
.join('')
|
||||
}
|
||||
|
||||
function findAliasType(typeString: string, abi: ABI.Def): string | undefined {
|
||||
const alias = abi.types.find((type) => type.new_type_name === typeString)
|
||||
|
||||
return alias?.type
|
||||
}
|
||||
|
||||
function findVariantType(
|
||||
typeString: string,
|
||||
namespace: string | null,
|
||||
abi: ABI.Def
|
||||
): string | undefined {
|
||||
const abiVariant = abi.variants.find(
|
||||
(variant) => variant.name.toLowerCase() === typeString.toLowerCase()
|
||||
)
|
||||
|
||||
if (!abiVariant) {
|
||||
return
|
||||
}
|
||||
|
||||
return abiVariant.types.join(' | ')
|
||||
}
|
||||
|
||||
export function findAbiType(type: string, abi: ABI.Def, typeNamespace = ''): string | undefined {
|
||||
let typeString = type
|
||||
|
||||
const aliasType = findAliasType(typeString, abi)
|
||||
|
||||
if (aliasType) {
|
||||
typeString = aliasType
|
||||
}
|
||||
|
||||
const variantType = findVariantType(typeString, typeNamespace, abi)
|
||||
|
||||
if (variantType) {
|
||||
typeString = variantType
|
||||
}
|
||||
|
||||
const abiType = abi.structs.find((abiType) => abiType.name === typeString)?.name
|
||||
|
||||
if (abiType) {
|
||||
return `${typeNamespace}${generateStructClassName(abiType)}`
|
||||
}
|
||||
}
|
||||
|
||||
export function findExternalType(type: string, abi: ABI.Def, typeNamespace?: string): string {
|
||||
let {type: typeString} = extractDecorator(type)
|
||||
const {decorator} = extractDecorator(type)
|
||||
|
||||
typeString = parseType(typeString)
|
||||
|
||||
const relevantAbitype = findAbiType(typeString, abi, typeNamespace)
|
||||
|
||||
if (relevantAbitype) {
|
||||
typeString = relevantAbitype
|
||||
}
|
||||
|
||||
return `${findCoreType(typeString) || capitalize(typeString)}${decorator === '[]' ? '[]' : ''}`
|
||||
}
|
||||
|
||||
const decorators = ['?', '[]']
|
||||
export function extractDecorator(type: string): {type: string; decorator?: string} {
|
||||
for (const decorator of decorators) {
|
||||
if (type.includes(decorator)) {
|
||||
type = type.replace(decorator, '')
|
||||
|
||||
return {type, decorator}
|
||||
}
|
||||
}
|
||||
|
||||
return {type}
|
||||
}
|
||||
|
||||
function parseType(type: string): string {
|
||||
return type.replace('$', '')
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
import {ABI} from '@wharfkit/antelope'
|
||||
import ts from 'typescript'
|
||||
import {capitalize} from '../utils'
|
||||
import {findExternalType} from './helpers'
|
||||
import {getActionFieldFromAbi} from './structs'
|
||||
|
||||
export function generateActionNamesInterface(abi: ABI.Def): ts.InterfaceDeclaration {
|
||||
// Generate property signatures for each action
|
||||
const members = abi.actions.map((action) => {
|
||||
const actionName = String(action.name)
|
||||
const actionNameCapitalized = capitalize(actionName)
|
||||
|
||||
return ts.factory.createPropertySignature(
|
||||
undefined,
|
||||
actionName,
|
||||
undefined,
|
||||
ts.factory.createTypeReferenceNode(`ActionParams.${actionNameCapitalized}`)
|
||||
)
|
||||
})
|
||||
|
||||
return ts.factory.createInterfaceDeclaration(
|
||||
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
||||
'ActionNameParams',
|
||||
undefined,
|
||||
undefined,
|
||||
members
|
||||
)
|
||||
}
|
||||
|
||||
export function generateActionInterface(actionStruct, abi): ts.InterfaceDeclaration {
|
||||
const members = actionStruct.fields.map((field) => {
|
||||
const typeReferenceNode = ts.factory.createTypeReferenceNode(
|
||||
findParamTypeString(field.type, 'Types.', abi)
|
||||
)
|
||||
|
||||
return ts.factory.createPropertySignature(
|
||||
undefined,
|
||||
field.name.toLowerCase(),
|
||||
field.type.includes('?')
|
||||
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
||||
: undefined,
|
||||
typeReferenceNode
|
||||
)
|
||||
})
|
||||
|
||||
return ts.factory.createInterfaceDeclaration(
|
||||
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
||||
capitalize(actionStruct.structName),
|
||||
undefined,
|
||||
undefined,
|
||||
members
|
||||
)
|
||||
}
|
||||
|
||||
export function generateActionsNamespace(abi: ABI.Def): ts.ModuleDeclaration {
|
||||
const actionStructsWithFields = getActionFieldFromAbi(abi)
|
||||
|
||||
const interfaces = abi.actions.map((action) => {
|
||||
const actionStruct = actionStructsWithFields.find(
|
||||
(actionStructWithField) => actionStructWithField.structName === action.type
|
||||
)
|
||||
return generateActionInterface(actionStruct, abi)
|
||||
})
|
||||
|
||||
return ts.factory.createModuleDeclaration(
|
||||
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
||||
ts.factory.createIdentifier('ActionParams'),
|
||||
ts.factory.createModuleBlock(interfaces),
|
||||
ts.NodeFlags.Namespace
|
||||
)
|
||||
}
|
||||
|
||||
function findParamTypeString(typeString: string, namespace: string | null, abi: ABI.Def): string {
|
||||
const fieldType = findExternalType(typeString, abi, namespace ? namespace : undefined)
|
||||
|
||||
if (fieldType === 'Symbol') {
|
||||
return 'Asset.SymbolType'
|
||||
}
|
||||
|
||||
if (fieldType === 'Bool') {
|
||||
return 'boolean'
|
||||
}
|
||||
|
||||
if (['String', 'Boolean', 'Number'].includes(fieldType)) {
|
||||
return fieldType.toLowerCase()
|
||||
}
|
||||
|
||||
return fieldType
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import {ABI} from '@wharfkit/antelope'
|
||||
import * as ts from 'typescript'
|
||||
import {findAbiType} from './helpers'
|
||||
|
||||
export function generateTableMap(abi: ABI.Def): ts.VariableStatement {
|
||||
// Map over tables to create the object properties
|
||||
const tableProperties = abi.tables.map((table) =>
|
||||
ts.factory.createPropertyAssignment(
|
||||
JSON.stringify(table.name),
|
||||
ts.factory.createIdentifier(findAbiType(table.type, abi, 'Types.') || table.type)
|
||||
)
|
||||
)
|
||||
|
||||
// Create the TableMap structure
|
||||
const tableMap = ts.factory.createObjectLiteralExpression(tableProperties, true)
|
||||
|
||||
// Declare the variable
|
||||
return ts.factory.createVariableStatement(
|
||||
undefined,
|
||||
ts.factory.createVariableDeclarationList(
|
||||
[
|
||||
ts.factory.createVariableDeclaration(
|
||||
ts.factory.createIdentifier('TableMap'),
|
||||
undefined,
|
||||
undefined,
|
||||
tableMap
|
||||
),
|
||||
],
|
||||
ts.NodeFlags.Const
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import * as ts from 'typescript'
|
||||
|
||||
import {capitalize} from '../utils'
|
||||
|
||||
// Generates a namespace name for a contract (eg. _EosioToken for eosio.token)
|
||||
export function generateNamespaceName(contractName: string) {
|
||||
return contractName
|
||||
.split('.')
|
||||
.map((namePart) => capitalize(namePart))
|
||||
.join('')
|
||||
}
|
||||
|
||||
export function generateNamespace(
|
||||
namespaceName: string,
|
||||
children,
|
||||
isExport = true
|
||||
): ts.ModuleDeclaration {
|
||||
return ts.factory.createModuleDeclaration(
|
||||
isExport ? [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)] : [], // modifiers
|
||||
ts.factory.createIdentifier(namespaceName),
|
||||
ts.factory.createModuleBlock(children),
|
||||
ts.NodeFlags.Namespace
|
||||
)
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
import {ABI} from '@wharfkit/session'
|
||||
import ts from 'typescript'
|
||||
import {capitalize} from '../utils'
|
||||
import {extractDecorator, findInternalType, generateStructClassName} from './helpers'
|
||||
|
||||
interface FieldType {
|
||||
name: string
|
||||
type: string
|
||||
}
|
||||
|
||||
interface StructData {
|
||||
structName: string
|
||||
fields: FieldType[]
|
||||
}
|
||||
|
||||
export function generateStructClasses(abi) {
|
||||
const structs = getActionFieldFromAbi(abi)
|
||||
const orderedStructs = orderStructs(structs)
|
||||
|
||||
const structMembers: ts.ClassDeclaration[] = []
|
||||
|
||||
for (const struct of orderedStructs) {
|
||||
structMembers.push(generateStruct(struct, abi, true))
|
||||
}
|
||||
|
||||
return structMembers
|
||||
}
|
||||
|
||||
export function getActionFieldFromAbi(abi: any): StructData[] {
|
||||
const structTypes: {structName: string; fields: FieldType[]}[] = []
|
||||
|
||||
if (abi && abi.structs) {
|
||||
for (const struct of abi.structs) {
|
||||
const fields: FieldType[] = []
|
||||
|
||||
for (const field of struct.fields) {
|
||||
fields.push({
|
||||
name: capitalize(field.name),
|
||||
type: field.type,
|
||||
})
|
||||
}
|
||||
|
||||
structTypes.push({structName: struct.name, fields})
|
||||
}
|
||||
}
|
||||
|
||||
return structTypes
|
||||
}
|
||||
|
||||
export function generateStruct(struct, abi, isExport = false): ts.ClassDeclaration {
|
||||
const decorators = [
|
||||
ts.factory.createDecorator(
|
||||
ts.factory.createCallExpression(ts.factory.createIdentifier('Struct.type'), undefined, [
|
||||
ts.factory.createStringLiteral(struct.structName),
|
||||
])
|
||||
),
|
||||
]
|
||||
|
||||
const members: ts.ClassElement[] = []
|
||||
|
||||
for (const field of struct.fields) {
|
||||
members.push(generateField(field, null, abi))
|
||||
}
|
||||
|
||||
return ts.factory.createClassDeclaration(
|
||||
isExport
|
||||
? [...decorators, ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)]
|
||||
: decorators,
|
||||
ts.factory.createIdentifier(generateStructClassName(struct.structName)),
|
||||
undefined, // typeParameters
|
||||
[
|
||||
ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
|
||||
ts.factory.createExpressionWithTypeArguments(
|
||||
ts.factory.createIdentifier('Struct'),
|
||||
[]
|
||||
),
|
||||
]),
|
||||
], // heritageClauses
|
||||
members // Pass the members array
|
||||
)
|
||||
}
|
||||
|
||||
export function generateField(
|
||||
field: FieldType,
|
||||
namespace: string | null,
|
||||
abi: ABI.Def
|
||||
): ts.PropertyDeclaration {
|
||||
const fieldName = field.name.toLowerCase()
|
||||
|
||||
const isArray = field.type.endsWith('[]')
|
||||
const isOptional = field.type.endsWith('?')
|
||||
|
||||
// Start with the main type argument
|
||||
const decoratorArguments: (ts.ObjectLiteralExpression | ts.StringLiteral | ts.Identifier)[] = [
|
||||
findFieldStructType(field.type, namespace, abi),
|
||||
]
|
||||
|
||||
// Build the options object if needed
|
||||
const optionsProps: ts.ObjectLiteralElementLike[] = []
|
||||
|
||||
if (isArray) {
|
||||
optionsProps.push(
|
||||
ts.factory.createPropertyAssignment(
|
||||
ts.factory.createIdentifier('array'),
|
||||
ts.factory.createTrue()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (isOptional) {
|
||||
optionsProps.push(
|
||||
ts.factory.createPropertyAssignment(
|
||||
ts.factory.createIdentifier('optional'),
|
||||
ts.factory.createTrue()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// If there are options, create the object and add to decorator arguments
|
||||
if (optionsProps.length > 0) {
|
||||
const optionsObject = ts.factory.createObjectLiteralExpression(optionsProps)
|
||||
decoratorArguments.push(optionsObject)
|
||||
}
|
||||
|
||||
const decorators = [
|
||||
ts.factory.createDecorator(
|
||||
ts.factory.createCallExpression(
|
||||
ts.factory.createIdentifier('Struct.field'),
|
||||
undefined,
|
||||
decoratorArguments
|
||||
)
|
||||
),
|
||||
]
|
||||
|
||||
let typeNode: ts.ArrayTypeNode | ts.TypeReferenceNode
|
||||
|
||||
const typeReferenceNode = ts.factory.createTypeReferenceNode(
|
||||
findFieldStructTypeString(field.type, namespace, abi)
|
||||
)
|
||||
|
||||
if (isArray) {
|
||||
typeNode = ts.factory.createArrayTypeNode(typeReferenceNode)
|
||||
} else {
|
||||
typeNode = typeReferenceNode
|
||||
}
|
||||
|
||||
return ts.factory.createPropertyDeclaration(
|
||||
decorators,
|
||||
ts.factory.createIdentifier(fieldName),
|
||||
ts.factory.createToken(
|
||||
isOptional ? ts.SyntaxKind.QuestionToken : ts.SyntaxKind.ExclamationToken
|
||||
),
|
||||
typeNode,
|
||||
undefined // initializer
|
||||
)
|
||||
}
|
||||
|
||||
function orderStructs(structs) {
|
||||
const orderedStructs: StructData[] = []
|
||||
|
||||
for (const struct of structs) {
|
||||
orderedStructs.push(...findDependencies(struct, structs))
|
||||
orderedStructs.push(struct)
|
||||
}
|
||||
|
||||
return orderedStructs.filter((struct, index, self) => {
|
||||
return index === self.findIndex((s) => s.structName === struct.structName)
|
||||
})
|
||||
}
|
||||
|
||||
function findDependencies(struct: StructData, allStructs: StructData[]): StructData[] {
|
||||
const dependencies: StructData[] = []
|
||||
|
||||
const structNames = allStructs.map((struct) => struct.structName)
|
||||
|
||||
for (const field of struct.fields) {
|
||||
const {type: fieldType} = extractDecorator(field.type)
|
||||
|
||||
if (structNames.includes(fieldType.toLowerCase())) {
|
||||
const dependencyStruct = allStructs.find(
|
||||
(struct) => struct.structName === fieldType.toLowerCase()
|
||||
)
|
||||
if (dependencyStruct) {
|
||||
dependencies.push(...findDependencies(dependencyStruct, allStructs))
|
||||
dependencies.push(dependencyStruct)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dependencies
|
||||
}
|
||||
|
||||
function findFieldStructType(
|
||||
typeString: string,
|
||||
namespace: string | null,
|
||||
abi: ABI.Def
|
||||
): ts.Identifier | ts.StringLiteral {
|
||||
const fieldTypeString = findFieldStructTypeString(typeString, namespace, abi)
|
||||
|
||||
if (['string', 'boolean', 'number'].includes(fieldTypeString)) {
|
||||
return ts.factory.createStringLiteral(fieldTypeString)
|
||||
}
|
||||
|
||||
return ts.factory.createIdentifier(fieldTypeString)
|
||||
}
|
||||
|
||||
function findFieldStructTypeString(
|
||||
typeString: string,
|
||||
namespace: string | null,
|
||||
abi: ABI.Def
|
||||
): string {
|
||||
const fieldType = findInternalType(typeString, namespace, abi)
|
||||
|
||||
if (['String', 'Number'].includes(fieldType)) {
|
||||
return fieldType.toLowerCase()
|
||||
}
|
||||
|
||||
if (fieldType === 'Bool') {
|
||||
return 'boolean'
|
||||
}
|
||||
|
||||
if (fieldType === 'Symbol') {
|
||||
return 'Asset.Symbol'
|
||||
}
|
||||
|
||||
return fieldType
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,365 +0,0 @@
|
||||
{
|
||||
"version": "eosio::abi/1.1",
|
||||
"types": [],
|
||||
"structs": [
|
||||
{
|
||||
"name": "action",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "account",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "authorization",
|
||||
"type": "permission_level[]"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"type": "bytes"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "approval",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "level",
|
||||
"type": "permission_level"
|
||||
},
|
||||
{
|
||||
"name": "time",
|
||||
"type": "time_point"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "approvals_info",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "version",
|
||||
"type": "uint8"
|
||||
},
|
||||
{
|
||||
"name": "proposal_name",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "requested_approvals",
|
||||
"type": "approval[]"
|
||||
},
|
||||
{
|
||||
"name": "provided_approvals",
|
||||
"type": "approval[]"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "approve",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "proposer",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "proposal_name",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "level",
|
||||
"type": "permission_level"
|
||||
},
|
||||
{
|
||||
"name": "proposal_hash",
|
||||
"type": "checksum256$"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "cancel",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "proposer",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "proposal_name",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "canceler",
|
||||
"type": "name"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "exec",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "proposer",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "proposal_name",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "executer",
|
||||
"type": "name"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "extension",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "type",
|
||||
"type": "uint16"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"type": "bytes"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "invalidate",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "account",
|
||||
"type": "name"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "invalidation",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "account",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "last_invalidation_time",
|
||||
"type": "time_point"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "old_approvals_info",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "proposal_name",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "requested_approvals",
|
||||
"type": "permission_level[]"
|
||||
},
|
||||
{
|
||||
"name": "provided_approvals",
|
||||
"type": "permission_level[]"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "permission_level",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "actor",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "permission",
|
||||
"type": "name"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "proposal",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "proposal_name",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "packed_transaction",
|
||||
"type": "bytes"
|
||||
},
|
||||
{
|
||||
"name": "earliest_exec_time",
|
||||
"type": "time_point?$"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "propose",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "proposer",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "proposal_name",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "requested",
|
||||
"type": "permission_level[]"
|
||||
},
|
||||
{
|
||||
"name": "trx",
|
||||
"type": "transaction"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "transaction",
|
||||
"base": "transaction_header",
|
||||
"fields": [
|
||||
{
|
||||
"name": "context_free_actions",
|
||||
"type": "action[]"
|
||||
},
|
||||
{
|
||||
"name": "actions",
|
||||
"type": "action[]"
|
||||
},
|
||||
{
|
||||
"name": "transaction_extensions",
|
||||
"type": "extension[]"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "transaction_header",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "expiration",
|
||||
"type": "time_point_sec"
|
||||
},
|
||||
{
|
||||
"name": "ref_block_num",
|
||||
"type": "uint16"
|
||||
},
|
||||
{
|
||||
"name": "ref_block_prefix",
|
||||
"type": "uint32"
|
||||
},
|
||||
{
|
||||
"name": "max_net_usage_words",
|
||||
"type": "varuint32"
|
||||
},
|
||||
{
|
||||
"name": "max_cpu_usage_ms",
|
||||
"type": "uint8"
|
||||
},
|
||||
{
|
||||
"name": "delay_sec",
|
||||
"type": "varuint32"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "unapprove",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "proposer",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "proposal_name",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "level",
|
||||
"type": "permission_level"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"name": "approve",
|
||||
"type": "approve",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Approve Proposed Transaction\nsummary: '{{nowrap level.actor}} approves the {{nowrap proposal_name}} proposal'\nicon: https://raw.githubusercontent.com/EOS-Nation/eosio.msig/master/contracts/icons/multisig.png#4fb41d3cf02d0dd2d35a29308e93c2d826ec770d6bb520db668f530764be7153\n---\n\n{{level.actor}} approves the {{proposal_name}} proposal proposed by {{proposer}} with the {{level.permission}} permission of {{level.actor}}."
|
||||
},
|
||||
{
|
||||
"name": "cancel",
|
||||
"type": "cancel",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Cancel Proposed Transaction\nsummary: '{{nowrap canceler}} cancels the {{nowrap proposal_name}} proposal'\nicon: https://raw.githubusercontent.com/EOS-Nation/eosio.msig/master/contracts/icons/multisig.png#4fb41d3cf02d0dd2d35a29308e93c2d826ec770d6bb520db668f530764be7153\n---\n\n{{canceler}} cancels the {{proposal_name}} proposal submitted by {{proposer}}."
|
||||
},
|
||||
{
|
||||
"name": "exec",
|
||||
"type": "exec",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Execute Proposed Transaction\nsummary: '{{nowrap executer}} executes the {{nowrap proposal_name}} proposal'\nicon: https://raw.githubusercontent.com/EOS-Nation/eosio.msig/master/contracts/icons/multisig.png#4fb41d3cf02d0dd2d35a29308e93c2d826ec770d6bb520db668f530764be7153\n---\n\n{{executer}} executes the {{proposal_name}} proposal submitted by {{proposer}} if the minimum required approvals for the proposal have been secured."
|
||||
},
|
||||
{
|
||||
"name": "invalidate",
|
||||
"type": "invalidate",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Invalidate All Approvals\nsummary: '{{nowrap account}} invalidates approvals on outstanding proposals'\nicon: https://raw.githubusercontent.com/EOS-Nation/eosio.msig/master/contracts/icons/multisig.png#4fb41d3cf02d0dd2d35a29308e93c2d826ec770d6bb520db668f530764be7153\n---\n\n{{account}} invalidates all approvals on proposals which have not yet executed."
|
||||
},
|
||||
{
|
||||
"name": "propose",
|
||||
"type": "propose",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Propose Transaction\nsummary: '{{nowrap proposer}} creates the {{nowrap proposal_name}}'\nicon: https://raw.githubusercontent.com/EOS-Nation/eosio.msig/master/contracts/icons/multisig.png#4fb41d3cf02d0dd2d35a29308e93c2d826ec770d6bb520db668f530764be7153\n---\n\n{{proposer}} creates the {{proposal_name}} proposal for the following transaction:\n{{to_json trx}}\n\nThe proposal requests approvals from the following accounts at the specified permission levels:\n{{#each requested}}\n + {{this.permission}} permission of {{this.actor}}\n{{/each}}\n\nIf the proposed transaction is not executed prior to {{trx.expiration}}, the proposal will automatically expire."
|
||||
},
|
||||
{
|
||||
"name": "unapprove",
|
||||
"type": "unapprove",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Unapprove Proposed Transaction\nsummary: '{{nowrap level.actor}} revokes the approval previously provided to {{nowrap proposal_name}} proposal'\nicon: https://raw.githubusercontent.com/EOS-Nation/eosio.msig/master/contracts/icons/multisig.png#4fb41d3cf02d0dd2d35a29308e93c2d826ec770d6bb520db668f530764be7153\n---\n\n{{level.actor}} revokes the approval previously provided at their {{level.permission}} permission level from the {{proposal_name}} proposal proposed by {{proposer}}."
|
||||
}
|
||||
],
|
||||
"tables": [
|
||||
{
|
||||
"name": "approvals",
|
||||
"index_type": "i64",
|
||||
"key_names": [],
|
||||
"key_types": [],
|
||||
"type": "old_approvals_info"
|
||||
},
|
||||
{
|
||||
"name": "approvals2",
|
||||
"index_type": "i64",
|
||||
"key_names": [],
|
||||
"key_types": [],
|
||||
"type": "approvals_info"
|
||||
},
|
||||
{
|
||||
"name": "invals",
|
||||
"index_type": "i64",
|
||||
"key_names": [],
|
||||
"key_types": [],
|
||||
"type": "invalidation"
|
||||
},
|
||||
{
|
||||
"name": "proposal",
|
||||
"index_type": "i64",
|
||||
"key_names": [],
|
||||
"key_types": [],
|
||||
"type": "proposal"
|
||||
}
|
||||
],
|
||||
"ricardian_clauses": [],
|
||||
"error_messages": [],
|
||||
"abi_extensions": [],
|
||||
"variants": [],
|
||||
"action_results": []
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
{
|
||||
"version": "eosio::abi/1.1",
|
||||
"types": [],
|
||||
"structs": [
|
||||
{
|
||||
"name": "account",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "balance",
|
||||
"type": "asset"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "close",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "owner",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "symbol",
|
||||
"type": "symbol"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "create",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "issuer",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "maximum_supply",
|
||||
"type": "asset"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "currency_stats",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "supply",
|
||||
"type": "asset"
|
||||
},
|
||||
{
|
||||
"name": "max_supply",
|
||||
"type": "asset"
|
||||
},
|
||||
{
|
||||
"name": "issuer",
|
||||
"type": "name"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "issue",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "to",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "quantity",
|
||||
"type": "asset"
|
||||
},
|
||||
{
|
||||
"name": "memo",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "open",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "owner",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "symbol",
|
||||
"type": "symbol"
|
||||
},
|
||||
{
|
||||
"name": "ram_payer",
|
||||
"type": "name"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "retire",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "quantity",
|
||||
"type": "asset"
|
||||
},
|
||||
{
|
||||
"name": "memo",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "transfer",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "from",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "to",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "quantity",
|
||||
"type": "asset"
|
||||
},
|
||||
{
|
||||
"name": "memo",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"name": "close",
|
||||
"type": "close",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Close Token Balance\nsummary: 'Close {{nowrap owner}}’s zero quantity balance'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/token.png#207ff68b0406eaa56618b08bda81d6a0954543f36adc328ab3065f31a5c5d654\n---\n\n{{owner}} agrees to close their zero quantity balance for the {{symbol_to_symbol_code symbol}} token.\n\nRAM will be refunded to the RAM payer of the {{symbol_to_symbol_code symbol}} token balance for {{owner}}."
|
||||
},
|
||||
{
|
||||
"name": "create",
|
||||
"type": "create",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Create New Token\nsummary: 'Create a new token'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/token.png#207ff68b0406eaa56618b08bda81d6a0954543f36adc328ab3065f31a5c5d654\n---\n\n{{$action.account}} agrees to create a new token with symbol {{asset_to_symbol_code maximum_supply}} to be managed by {{issuer}}.\n\nThis action will not result any any tokens being issued into circulation.\n\n{{issuer}} will be allowed to issue tokens into circulation, up to a maximum supply of {{maximum_supply}}.\n\nRAM will deducted from {{$action.account}}’s resources to create the necessary records."
|
||||
},
|
||||
{
|
||||
"name": "issue",
|
||||
"type": "issue",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Issue Tokens into Circulation\nsummary: 'Issue {{nowrap quantity}} into circulation and transfer into {{nowrap to}}’s account'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/token.png#207ff68b0406eaa56618b08bda81d6a0954543f36adc328ab3065f31a5c5d654\n---\n\nThe token manager agrees to issue {{quantity}} into circulation, and transfer it into {{to}}’s account.\n\n{{#if memo}}There is a memo attached to the transfer stating:\n{{memo}}\n{{/if}}\n\nIf {{to}} does not have a balance for {{asset_to_symbol_code quantity}}, or the token manager does not have a balance for {{asset_to_symbol_code quantity}}, the token manager will be designated as the RAM payer of the {{asset_to_symbol_code quantity}} token balance for {{to}}. As a result, RAM will be deducted from the token manager’s resources to create the necessary records.\n\nThis action does not allow the total quantity to exceed the max allowed supply of the token."
|
||||
},
|
||||
{
|
||||
"name": "open",
|
||||
"type": "open",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Open Token Balance\nsummary: 'Open a zero quantity balance for {{nowrap owner}}'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/token.png#207ff68b0406eaa56618b08bda81d6a0954543f36adc328ab3065f31a5c5d654\n---\n\n{{ram_payer}} agrees to establish a zero quantity balance for {{owner}} for the {{symbol_to_symbol_code symbol}} token.\n\nIf {{owner}} does not have a balance for {{symbol_to_symbol_code symbol}}, {{ram_payer}} will be designated as the RAM payer of the {{symbol_to_symbol_code symbol}} token balance for {{owner}}. As a result, RAM will be deducted from {{ram_payer}}’s resources to create the necessary records."
|
||||
},
|
||||
{
|
||||
"name": "retire",
|
||||
"type": "retire",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Remove Tokens from Circulation\nsummary: 'Remove {{nowrap quantity}} from circulation'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/token.png#207ff68b0406eaa56618b08bda81d6a0954543f36adc328ab3065f31a5c5d654\n---\n\nThe token manager agrees to remove {{quantity}} from circulation, taken from their own account.\n\n{{#if memo}} There is a memo attached to the action stating:\n{{memo}}\n{{/if}}"
|
||||
},
|
||||
{
|
||||
"name": "transfer",
|
||||
"type": "transfer",
|
||||
"ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Transfer Tokens\nsummary: 'Send {{nowrap quantity}} from {{nowrap from}} to {{nowrap to}}'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/transfer.png#5dfad0df72772ee1ccc155e670c1d124f5c5122f1d5027565df38b418042d1dd\n---\n\n{{from}} agrees to send {{quantity}} to {{to}}.\n\n{{#if memo}}There is a memo attached to the transfer stating:\n{{memo}}\n{{/if}}\n\nIf {{from}} is not already the RAM payer of their {{asset_to_symbol_code quantity}} token balance, {{from}} will be designated as such. As a result, RAM will be deducted from {{from}}’s resources to refund the original RAM payer.\n\nIf {{to}} does not have a balance for {{asset_to_symbol_code quantity}}, {{from}} will be designated as the RAM payer of the {{asset_to_symbol_code quantity}} token balance for {{to}}. As a result, RAM will be deducted from {{from}}’s resources to create the necessary records."
|
||||
}
|
||||
],
|
||||
"tables": [
|
||||
{
|
||||
"name": "accounts",
|
||||
"index_type": "i64",
|
||||
"key_names": [],
|
||||
"key_types": [],
|
||||
"type": "account"
|
||||
},
|
||||
{
|
||||
"name": "stat",
|
||||
"index_type": "i64",
|
||||
"key_names": [],
|
||||
"key_types": [],
|
||||
"type": "currency_stats"
|
||||
}
|
||||
],
|
||||
"ricardian_clauses": [],
|
||||
"error_messages": [],
|
||||
"abi_extensions": [],
|
||||
"variants": [],
|
||||
"action_results": []
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,160 +0,0 @@
|
||||
import {
|
||||
ABI,
|
||||
Action,
|
||||
Asset,
|
||||
AssetType,
|
||||
Blob,
|
||||
Float64,
|
||||
Name,
|
||||
NameType,
|
||||
Struct,
|
||||
TimePoint,
|
||||
UInt16,
|
||||
UInt16Type,
|
||||
} from '@wharfkit/antelope'
|
||||
import {ActionOptions, Contract as BaseContract, ContractArgs, PartialBy} from '@wharfkit/contract'
|
||||
export namespace RewardsGm {
|
||||
export const abiBlob = Blob.from(
|
||||
'DmVvc2lvOjphYmkvMS4yAAoHYWRkdXNlcgACB2FjY291bnQEbmFtZQZ3ZWlnaHQGdWludDE2BWNsYWltAAIHYWNjb3VudARuYW1lBmFtb3VudAZhc3NldD8GY29uZmlnAAMMdG9rZW5fc3ltYm9sBnN5bWJvbA5vcmFjbGVfYWNjb3VudARuYW1lDG9yYWNsZV9wYWlycw1vcmFjbGVfcGFpcltdCWNvbmZpZ3VyZQADDHRva2VuX3N5bWJvbAZzeW1ib2wOb3JhY2xlX2FjY291bnQEbmFtZQxvcmFjbGVfcGFpcnMNb3JhY2xlX3BhaXJbXQdkZWx1c2VyAAEHYWNjb3VudARuYW1lC29yYWNsZV9wYWlyAAIEbmFtZQRuYW1lCXByZWNpc2lvbgZ1aW50MTYKcHJpY2VfaW5mbwADBHBhaXIGc3RyaW5nBXByaWNlB2Zsb2F0NjQJdGltZXN0YW1wCnRpbWVfcG9pbnQHcmVjZWlwdAADB2FjY291bnQEbmFtZQZhbW91bnQFYXNzZXQGdGlja2VyDHByaWNlX2luZm9bXQp1cGRhdGV1c2VyAAIHYWNjb3VudARuYW1lBndlaWdodAZ1aW50MTYIdXNlcl9yb3cAAwdhY2NvdW50BG5hbWUGd2VpZ2h0BnVpbnQxNgdiYWxhbmNlBWFzc2V0BgAAAOAqrFMyB2FkZHVzZXKVAi0tLQpzcGVjX3ZlcnNpb246ICIwLjIuMCIKdGl0bGU6IEFkZCB1c2VyCnN1bW1hcnk6ICdBZGQgbmV3IHVzZXIge3tub3dyYXAgYWNjb3VudH19JwppY29uOiBodHRwczovL2FsbW9zdC5kaWdpdGFsL2ltYWdlcy9taXNjX2ljb24ucG5nIzZmNWVhOTc4YjA0ZDAzZTAxOGIzNzlhMmJhYzRjMTBiNWE4ZmUwY2Q1ZTZlMTVjODg4MjhkYzk4NmJlOTZjZmYKLS0tCgp7e2FjY291bnR9fSBpcyBhZGRlZCB0byB0aGUgcmV3YXJkcyBzaGFyaW5nIGxpc3Qgd2l0aCB3ZWlnaHQge3t3ZWlnaHR9fS4AAAAAAOlMRAVjbGFpbfYCLS0tCnNwZWNfdmVyc2lvbjogIjAuMi4wIgp0aXRsZTogQ2xhaW0Kc3VtbWFyeTogJ0NsYWltIHJld2FyZHMgZm9yIHt7bm93cmFwIGFjY291bnR9fScKaWNvbjogaHR0cHM6Ly9hbG1vc3QuZGlnaXRhbC9pbWFnZXMvY2xhaW1faWNvbi5wbmcjYmI1OTdmNGFjYzEzMDU5MjU5MTJlMThlN2I0Y2Y3MDhkMWZhZWMyYWE4OGI3YTUzZDg3OTY5ZTA0NTE2OGVjZgotLS0KCnt7I2lmX2hhc192YWx1ZSBhbW91bnR9fQogICAge3thY2NvdW50fX0gY2xhaW1zIHt7YW1vdW50fX0gZnJvbSB0aGVpciByZXdhcmRzIGJhbGFuY2UuCnt7ZWxzZX19CiAgICB7e2FjY291bnR9fSBjbGFpbXMgdGhlaXIgZW50aXJlIHJld2FyZHMgYmFsYW5jZS4Ke3svaWZfaGFzX3ZhbHVlfX0AAFBXM7cmRQljb25maWd1cmUAAAAA4Cqso0oHZGVsdXNlcsQCLS0tCnNwZWNfdmVyc2lvbjogIjAuMi4wIgp0aXRsZTogRGVsZXRlIHVzZXIKc3VtbWFyeTogJ0RlbGV0ZSB1c2VyIHt7bm93cmFwIGFjY291bnR9fScKaWNvbjogaHR0cHM6Ly9hbG1vc3QuZGlnaXRhbC9pbWFnZXMvbWlzY19pY29uLnBuZyM2ZjVlYTk3OGIwNGQwM2UwMThiMzc5YTJiYWM0YzEwYjVhOGZlMGNkNWU2ZTE1Yzg4ODI4ZGM5ODZiZTk2Y2ZmCi0tLQoKe3thY2NvdW50fX0gaXMgaXMgcmVtb3ZlZCBmcm9tIHRoZSByZXdhcmRzIHNoYXJpbmcgbGlzdC4KClVzZXJzIGNhbiBvbmx5IGJlIHJlbW92ZWQgaWYgdGhlaXIgcmV3YXJkcyBiYWxhbmNlIGlzIHplcm8uAAAAIFenkLoHcmVjZWlwdAAAwFVYq2xS1Qp1cGRhdGV1c2VygAItLS0Kc3BlY192ZXJzaW9uOiAiMC4yLjAiCnRpdGxlOiBVcGRhdGUgdXNlcgpzdW1tYXJ5OiAnVXBkYXRlIHVzZXIge3tub3dyYXAgYWNjb3VudH19JwppY29uOiBodHRwczovL2FsbW9zdC5kaWdpdGFsL2ltYWdlcy9taXNjX2ljb24ucG5nIzZmNWVhOTc4YjA0ZDAzZTAxOGIzNzlhMmJhYzRjMTBiNWE4ZmUwY2Q1ZTZlMTVjODg4MjhkYzk4NmJlOTZjZmYKLS0tCgp7e2FjY291bnR9fSBpcyB1cGRhdGVkIHRvIGhhdmUgd2VpZ2h0IHt7d2VpZ2h0fX0uAgAAAAAwtyZFA2k2NAAABmNvbmZpZwAAAAAAfBXWA2k2NAAACHVzZXJfcm93AAAAAA=='
|
||||
)
|
||||
export const abi = ABI.from(abiBlob)
|
||||
export class Contract extends BaseContract {
|
||||
constructor(args: PartialBy<ContractArgs, 'abi' | 'account'>) {
|
||||
super({
|
||||
client: args.client,
|
||||
abi: abi,
|
||||
account: Name.from('rewards.gm'),
|
||||
})
|
||||
}
|
||||
action<T extends 'adduser' | 'claim' | 'configure' | 'deluser' | 'receipt' | 'updateuser'>(
|
||||
name: T,
|
||||
data: ActionNameParams[T],
|
||||
options?: ActionOptions
|
||||
): Action {
|
||||
return super.action(name, data, options)
|
||||
}
|
||||
table<T extends 'config' | 'users'>(name: T, scope?: NameType) {
|
||||
return super.table(name, scope, TableMap[name])
|
||||
}
|
||||
}
|
||||
export interface ActionNameParams {
|
||||
adduser: ActionParams.Adduser
|
||||
claim: ActionParams.Claim
|
||||
configure: ActionParams.Configure
|
||||
deluser: ActionParams.Deluser
|
||||
receipt: ActionParams.Receipt
|
||||
updateuser: ActionParams.Updateuser
|
||||
}
|
||||
export namespace ActionParams {
|
||||
export interface Adduser {
|
||||
account: NameType
|
||||
weight: UInt16Type
|
||||
}
|
||||
export interface Claim {
|
||||
account: NameType
|
||||
amount?: AssetType
|
||||
}
|
||||
export interface Configure {
|
||||
token_symbol: Asset.SymbolType
|
||||
oracle_account: NameType
|
||||
oracle_pairs: Types.OraclePair[]
|
||||
}
|
||||
export interface Deluser {
|
||||
account: NameType
|
||||
}
|
||||
export interface Receipt {
|
||||
account: NameType
|
||||
amount: AssetType
|
||||
ticker: Types.PriceInfo[]
|
||||
}
|
||||
export interface Updateuser {
|
||||
account: NameType
|
||||
weight: UInt16Type
|
||||
}
|
||||
}
|
||||
export namespace Types {
|
||||
@Struct.type('adduser')
|
||||
export class Adduser extends Struct {
|
||||
@Struct.field(Name)
|
||||
account!: Name
|
||||
@Struct.field(UInt16)
|
||||
weight!: UInt16
|
||||
}
|
||||
@Struct.type('claim')
|
||||
export class Claim extends Struct {
|
||||
@Struct.field(Name)
|
||||
account!: Name
|
||||
@Struct.field(Asset, {optional: true})
|
||||
amount?: Asset
|
||||
}
|
||||
@Struct.type('oracle_pair')
|
||||
export class OraclePair extends Struct {
|
||||
@Struct.field(Name)
|
||||
name!: Name
|
||||
@Struct.field(UInt16)
|
||||
precision!: UInt16
|
||||
}
|
||||
@Struct.type('config')
|
||||
export class Config extends Struct {
|
||||
@Struct.field(Asset.Symbol)
|
||||
token_symbol!: Asset.Symbol
|
||||
@Struct.field(Name)
|
||||
oracle_account!: Name
|
||||
@Struct.field(OraclePair, {array: true})
|
||||
oracle_pairs!: OraclePair[]
|
||||
}
|
||||
@Struct.type('configure')
|
||||
export class Configure extends Struct {
|
||||
@Struct.field(Asset.Symbol)
|
||||
token_symbol!: Asset.Symbol
|
||||
@Struct.field(Name)
|
||||
oracle_account!: Name
|
||||
@Struct.field(OraclePair, {array: true})
|
||||
oracle_pairs!: OraclePair[]
|
||||
}
|
||||
@Struct.type('deluser')
|
||||
export class Deluser extends Struct {
|
||||
@Struct.field(Name)
|
||||
account!: Name
|
||||
}
|
||||
@Struct.type('price_info')
|
||||
export class PriceInfo extends Struct {
|
||||
@Struct.field('string')
|
||||
pair!: string
|
||||
@Struct.field(Float64)
|
||||
price!: Float64
|
||||
@Struct.field(TimePoint)
|
||||
timestamp!: TimePoint
|
||||
}
|
||||
@Struct.type('receipt')
|
||||
export class Receipt extends Struct {
|
||||
@Struct.field(Name)
|
||||
account!: Name
|
||||
@Struct.field(Asset)
|
||||
amount!: Asset
|
||||
@Struct.field(PriceInfo, {array: true})
|
||||
ticker!: PriceInfo[]
|
||||
}
|
||||
@Struct.type('updateuser')
|
||||
export class Updateuser extends Struct {
|
||||
@Struct.field(Name)
|
||||
account!: Name
|
||||
@Struct.field(UInt16)
|
||||
weight!: UInt16
|
||||
}
|
||||
@Struct.type('user_row')
|
||||
export class UserRow extends Struct {
|
||||
@Struct.field(Name)
|
||||
account!: Name
|
||||
@Struct.field(UInt16)
|
||||
weight!: UInt16
|
||||
@Struct.field(Asset)
|
||||
balance!: Asset
|
||||
}
|
||||
}
|
||||
const TableMap = {
|
||||
config: Types.Config,
|
||||
users: Types.UserRow,
|
||||
}
|
||||
}
|
||||
export default RewardsGm
|
||||
@@ -1,320 +0,0 @@
|
||||
// import {Contract, GetTableRowsOptions, Table, TableCursor} from '@wharfkit/contract'
|
||||
// import {
|
||||
// APIClient,
|
||||
// Asset,
|
||||
// AssetType,
|
||||
// Checksum256,
|
||||
// Checksum256Type,
|
||||
// Float64,
|
||||
// Float64Type,
|
||||
// Name,
|
||||
// NameType,
|
||||
// Session,
|
||||
// Struct,
|
||||
// TimePoint,
|
||||
// TimePointSec,
|
||||
// TimePointType,
|
||||
// TransactResult,
|
||||
// UInt128,
|
||||
// UInt128Type,
|
||||
// UInt16,
|
||||
// UInt16Type,
|
||||
// UInt32,
|
||||
// UInt32Type,
|
||||
// UInt64,
|
||||
// UInt64Type,
|
||||
// UInt8,
|
||||
// UInt8Type,
|
||||
// } from '@wharfkit/session'
|
||||
|
||||
// export namespace _EosioToken {
|
||||
// export namespace actions {
|
||||
// export function close(
|
||||
// closeParams: _EosioToken.types.CloseParams,
|
||||
// session: Session
|
||||
// ): Promise<TransactResult> {
|
||||
// const contract = Contract.from({name: 'eosio.token'})
|
||||
// return contract.call('close', _EosioToken.types.Close.from(closeParams), session)
|
||||
// }
|
||||
// export function create(
|
||||
// createParams: _EosioToken.types.CreateParams,
|
||||
// session: Session
|
||||
// ): Promise<TransactResult> {
|
||||
// const contract = Contract.from({name: 'eosio.token'})
|
||||
// return contract.call('create', _EosioToken.types.Create.from(createParams), session)
|
||||
// }
|
||||
// export function issue(
|
||||
// issueParams: _EosioToken.types.IssueParams,
|
||||
// session: Session
|
||||
// ): Promise<TransactResult> {
|
||||
// const contract = Contract.from({name: 'eosio.token'})
|
||||
// return contract.call('issue', _EosioToken.types.Issue.from(issueParams), session)
|
||||
// }
|
||||
// export function open(
|
||||
// openParams: _EosioToken.types.OpenParams,
|
||||
// session: Session
|
||||
// ): Promise<TransactResult> {
|
||||
// const contract = Contract.from({name: 'eosio.token'})
|
||||
// return contract.call('open', _EosioToken.types.Open.from(openParams), session)
|
||||
// }
|
||||
// export function retire(
|
||||
// retireParams: _EosioToken.types.RetireParams,
|
||||
// session: Session
|
||||
// ): Promise<TransactResult> {
|
||||
// const contract = Contract.from({name: 'eosio.token'})
|
||||
// return contract.call('retire', _EosioToken.types.Retire.from(retireParams), session)
|
||||
// }
|
||||
// export function transfer(
|
||||
// transferParams: _EosioToken.types.TransferParams,
|
||||
// session: Session
|
||||
// ): Promise<TransactResult> {
|
||||
// const contract = Contract.from({name: 'eosio.token'})
|
||||
// return contract.call(
|
||||
// 'transfer',
|
||||
// _EosioToken.types.Transfer.from(transferParams),
|
||||
// session
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// export namespace _EosioToken {
|
||||
// export namespace tables {
|
||||
// export class accounts {
|
||||
// static fieldToIndex = {balance: {type: 'balance', index_position: 'primary'}}
|
||||
// static query(
|
||||
// queryParams: _EosioToken.types.AccountsQueryParams,
|
||||
// getTableRowsOptions: GetTableRowsOptions,
|
||||
// client: APIClient
|
||||
// ): TableCursor<_EosioToken.types.Account> {
|
||||
// const accountsTable = Table.from({
|
||||
// contract: Contract.from({name: 'eosio.token', client: client}),
|
||||
// name: 'accounts',
|
||||
// rowType: _EosioToken.types.Account,
|
||||
// fieldToIndex: accounts.fieldToIndex,
|
||||
// })
|
||||
// return accountsTable.query(queryParams, getTableRowsOptions)
|
||||
// }
|
||||
// static get(
|
||||
// queryParams: _EosioToken.types.AccountsFindQueryParams,
|
||||
// client: APIClient
|
||||
// ): Promise<_EosioToken.types.Account> {
|
||||
// const accountsTable = Table.from({
|
||||
// contract: Contract.from({name: 'eosio.token', client: client}),
|
||||
// name: 'accounts',
|
||||
// rowType: _EosioToken.types.Account,
|
||||
// fieldToIndex: accounts.fieldToIndex,
|
||||
// })
|
||||
// return accountsTable.get(queryParams)
|
||||
// }
|
||||
// static first(limit: number, client: APIClient): TableCursor<_EosioToken.types.Account> {
|
||||
// const accountsTable = Table.from({
|
||||
// contract: Contract.from({name: 'eosio.token', client: client}),
|
||||
// name: 'accounts',
|
||||
// rowType: _EosioToken.types.Account,
|
||||
// fieldToIndex: accounts.fieldToIndex,
|
||||
// })
|
||||
// return accountsTable.first(limit)
|
||||
// }
|
||||
// static cursor(client: APIClient): TableCursor<_EosioToken.types.Account> {
|
||||
// const accountsTable = Table.from({
|
||||
// contract: Contract.from({name: 'eosio.token', client: client}),
|
||||
// name: 'accounts',
|
||||
// rowType: _EosioToken.types.Account,
|
||||
// fieldToIndex: accounts.fieldToIndex,
|
||||
// })
|
||||
// return accountsTable.cursor()
|
||||
// }
|
||||
// static all(client: APIClient): Promise<_EosioToken.types.Account[]> {
|
||||
// const accountsTable = Table.from({
|
||||
// contract: Contract.from({name: 'eosio.token', client: client}),
|
||||
// name: 'accounts',
|
||||
// rowType: _EosioToken.types.Account,
|
||||
// fieldToIndex: accounts.fieldToIndex,
|
||||
// })
|
||||
// return accountsTable.all()
|
||||
// }
|
||||
// }
|
||||
// export class stat {
|
||||
// static fieldToIndex = {supply: {type: 'supply', index_position: 'primary'}}
|
||||
// static query(
|
||||
// queryParams: _EosioToken.types.StatQueryParams,
|
||||
// getTableRowsOptions: GetTableRowsOptions,
|
||||
// client: APIClient
|
||||
// ): TableCursor<_EosioToken.types.Currency_stats> {
|
||||
// const statTable = Table.from({
|
||||
// contract: Contract.from({name: 'eosio.token', client: client}),
|
||||
// name: 'stat',
|
||||
// rowType: _EosioToken.types.Currency_stats,
|
||||
// fieldToIndex: stat.fieldToIndex,
|
||||
// })
|
||||
// return statTable.query(queryParams, getTableRowsOptions)
|
||||
// }
|
||||
// static get(
|
||||
// queryParams: _EosioToken.types.StatFindQueryParams,
|
||||
// client: APIClient
|
||||
// ): Promise<_EosioToken.types.Currency_stats> {
|
||||
// const statTable = Table.from({
|
||||
// contract: Contract.from({name: 'eosio.token', client: client}),
|
||||
// name: 'stat',
|
||||
// rowType: _EosioToken.types.Currency_stats,
|
||||
// fieldToIndex: stat.fieldToIndex,
|
||||
// })
|
||||
// return statTable.get(queryParams)
|
||||
// }
|
||||
// static first(
|
||||
// limit: number,
|
||||
// client: APIClient
|
||||
// ): TableCursor<_EosioToken.types.Currency_stats> {
|
||||
// const statTable = Table.from({
|
||||
// contract: Contract.from({name: 'eosio.token', client: client}),
|
||||
// name: 'stat',
|
||||
// rowType: _EosioToken.types.Currency_stats,
|
||||
// fieldToIndex: stat.fieldToIndex,
|
||||
// })
|
||||
// return statTable.first(limit)
|
||||
// }
|
||||
// static cursor(client: APIClient): TableCursor<_EosioToken.types.Currency_stats> {
|
||||
// const statTable = Table.from({
|
||||
// contract: Contract.from({name: 'eosio.token', client: client}),
|
||||
// name: 'stat',
|
||||
// rowType: _EosioToken.types.Currency_stats,
|
||||
// fieldToIndex: stat.fieldToIndex,
|
||||
// })
|
||||
// return statTable.cursor()
|
||||
// }
|
||||
// static all(client: APIClient): Promise<_EosioToken.types.Currency_stats[]> {
|
||||
// const statTable = Table.from({
|
||||
// contract: Contract.from({name: 'eosio.token', client: client}),
|
||||
// name: 'stat',
|
||||
// rowType: _EosioToken.types.Currency_stats,
|
||||
// fieldToIndex: stat.fieldToIndex,
|
||||
// })
|
||||
// return statTable.all()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// export namespace _EosioToken {
|
||||
// export namespace types {
|
||||
// export interface CloseParams {
|
||||
// owner: NameType
|
||||
// symbol: symbol
|
||||
// }
|
||||
// export interface CreateParams {
|
||||
// issuer: NameType
|
||||
// maximum_supply: AssetType
|
||||
// }
|
||||
// export interface IssueParams {
|
||||
// to: NameType
|
||||
// quantity: AssetType
|
||||
// memo: string
|
||||
// }
|
||||
// export interface OpenParams {
|
||||
// owner: NameType
|
||||
// symbol: symbol
|
||||
// ram_payer: NameType
|
||||
// }
|
||||
// export interface RetireParams {
|
||||
// quantity: AssetType
|
||||
// memo: string
|
||||
// }
|
||||
// export interface TransferParams {
|
||||
// from: NameType
|
||||
// to: NameType
|
||||
// quantity: AssetType
|
||||
// memo: string
|
||||
// }
|
||||
// export interface AccountsQueryParams {
|
||||
// balance?: {
|
||||
// from: AssetType
|
||||
// to: AssetType
|
||||
// }
|
||||
// }
|
||||
// export interface AccountsFindQueryParams {
|
||||
// balance?: AssetType
|
||||
// }
|
||||
// export interface StatQueryParams {
|
||||
// supply?: {
|
||||
// from: AssetType
|
||||
// to: AssetType
|
||||
// }
|
||||
// max_supply?: {
|
||||
// from: AssetType
|
||||
// to: AssetType
|
||||
// }
|
||||
// issuer?: {
|
||||
// from: NameType
|
||||
// to: NameType
|
||||
// }
|
||||
// }
|
||||
// export interface StatFindQueryParams {
|
||||
// supply?: AssetType
|
||||
// max_supply?: AssetType
|
||||
// issuer?: NameType
|
||||
// }
|
||||
// @Struct.type('account')
|
||||
// export class Account extends Struct {
|
||||
// @Struct.field('asset')
|
||||
// declare balance: Asset
|
||||
// }
|
||||
// @Struct.type('close')
|
||||
// export class Close extends Struct {
|
||||
// @Struct.field('name')
|
||||
// declare owner: Name
|
||||
// @Struct.field('symbol')
|
||||
// declare symbol: symbol
|
||||
// }
|
||||
// @Struct.type('create')
|
||||
// export class Create extends Struct {
|
||||
// @Struct.field('name')
|
||||
// declare issuer: Name
|
||||
// @Struct.field('asset')
|
||||
// declare maximum_supply: Asset
|
||||
// }
|
||||
// @Struct.type('currency_stats')
|
||||
// export class Currency_stats extends Struct {
|
||||
// @Struct.field('asset')
|
||||
// declare supply: Asset
|
||||
// @Struct.field('asset')
|
||||
// declare max_supply: Asset
|
||||
// @Struct.field('name')
|
||||
// declare issuer: Name
|
||||
// }
|
||||
// @Struct.type('issue')
|
||||
// export class Issue extends Struct {
|
||||
// @Struct.field('name')
|
||||
// declare to: Name
|
||||
// @Struct.field('asset')
|
||||
// declare quantity: Asset
|
||||
// @Struct.field('string')
|
||||
// declare memo: string
|
||||
// }
|
||||
// @Struct.type('open')
|
||||
// export class Open extends Struct {
|
||||
// @Struct.field('name')
|
||||
// declare owner: Name
|
||||
// @Struct.field('symbol')
|
||||
// declare symbol: symbol
|
||||
// @Struct.field('name')
|
||||
// declare ram_payer: Name
|
||||
// }
|
||||
// @Struct.type('retire')
|
||||
// export class Retire extends Struct {
|
||||
// @Struct.field('asset')
|
||||
// declare quantity: Asset
|
||||
// @Struct.field('string')
|
||||
// declare memo: string
|
||||
// }
|
||||
// @Struct.type('transfer')
|
||||
// export class Transfer extends Struct {
|
||||
// @Struct.field('name')
|
||||
// declare from: Name
|
||||
// @Struct.field('name')
|
||||
// declare to: Name
|
||||
// @Struct.field('asset')
|
||||
// declare quantity: Asset
|
||||
// @Struct.field('string')
|
||||
// declare memo: string
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -1,129 +0,0 @@
|
||||
import {ABI, APIClient, Name} from '@wharfkit/antelope'
|
||||
import {makeClient} from '@wharfkit/mock-data'
|
||||
import {assert} from 'chai'
|
||||
import fs from 'fs'
|
||||
import {Contract} from 'src/contract'
|
||||
|
||||
import Eosio from '$test/data/contracts/mock-eosio'
|
||||
import EosioMsig from '$test/data/contracts/mock-eosio.msig'
|
||||
import EosioToken from '$test/data/contracts/mock-eosio.token'
|
||||
import RewardsGm from '$test/data/contracts/mock-rewards.gm'
|
||||
|
||||
import {generateCodegenContract, removeCodegenContracts} from '$test/utils/codegen'
|
||||
import {runGenericContractTests} from './helpers/generic'
|
||||
|
||||
const client = makeClient('https://eos.greymass.com')
|
||||
|
||||
interface Code {
|
||||
mock: string
|
||||
generated: string
|
||||
}
|
||||
|
||||
suite('codegen', async function () {
|
||||
// Contract instances
|
||||
const contracts = {
|
||||
eosio: {
|
||||
mock: Eosio,
|
||||
generated: null,
|
||||
},
|
||||
'eosio.msig': {
|
||||
mock: EosioMsig,
|
||||
generated: null,
|
||||
},
|
||||
'eosio.token': {
|
||||
mock: EosioToken,
|
||||
generated: null,
|
||||
},
|
||||
'rewards.gm': {
|
||||
mock: RewardsGm,
|
||||
generated: null,
|
||||
},
|
||||
}
|
||||
|
||||
// Source code
|
||||
const sources: Code[] = []
|
||||
|
||||
setup(async function () {
|
||||
if (!sources.length) {
|
||||
// loop through files
|
||||
for (const testCase of Object.keys(contracts)) {
|
||||
const generated = await generateCodegenContract(testCase)
|
||||
const mock = fs
|
||||
.readFileSync(`test/data/contracts/mock-${testCase}.ts`)
|
||||
.toString('utf-8')
|
||||
// Push source file in for comparison
|
||||
sources.push({
|
||||
mock,
|
||||
generated: generated.text,
|
||||
})
|
||||
// Push contract class for testing
|
||||
contracts[testCase] = generated.import
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
suite('Generated vs Static', function () {
|
||||
test('Contracts are identical', function () {
|
||||
for (const source of sources) {
|
||||
assert.equal(source.generated, source.mock)
|
||||
}
|
||||
})
|
||||
for (const contractKey of Object.keys(contracts)) {
|
||||
for (const testType of Object.keys(contracts[contractKey])) {
|
||||
test(`Testing contract ${contractKey} (${testType})`, function () {
|
||||
const testNamespace = contracts[contractKey].default
|
||||
const testContract = testNamespace.Contract
|
||||
const testContractInstance = new testContract({client})
|
||||
|
||||
// Run generic contract tests
|
||||
runGenericContractTests(testContractInstance)
|
||||
|
||||
function assertRewardsContract(contract) {
|
||||
assert.instanceOf(contract, Contract)
|
||||
assert.instanceOf(contract.abi, ABI)
|
||||
assert.isTrue(contract.abi.equals(testNamespace.abi))
|
||||
assert.instanceOf(contract.account, Name)
|
||||
assert.instanceOf(contract.client, APIClient)
|
||||
}
|
||||
|
||||
assertRewardsContract(testContractInstance)
|
||||
|
||||
const c1 = new testContract({client})
|
||||
assertRewardsContract(c1)
|
||||
|
||||
const c2 = new testContract({client, abi: testNamespace.abi})
|
||||
assertRewardsContract(c2)
|
||||
|
||||
const c3 = new testContract({client, account: 'teamgreymass'})
|
||||
assertRewardsContract(c3)
|
||||
|
||||
const c4 = new testContract({
|
||||
client,
|
||||
account: Name.from('teamgreymass'),
|
||||
})
|
||||
assertRewardsContract(c4)
|
||||
|
||||
const c5 = new testContract({
|
||||
client,
|
||||
abi: testNamespace.abi,
|
||||
account: 'teamgreymass',
|
||||
})
|
||||
assertRewardsContract(c5)
|
||||
|
||||
assert.throws(() => new testContract({abi: testNamespace.abi}))
|
||||
assert.throws(
|
||||
() =>
|
||||
new testContract({
|
||||
abi: testNamespace.abi,
|
||||
account: 'teamgreymass',
|
||||
})
|
||||
)
|
||||
assert.throws(() => new testContract({account: 'teamgreymass'}))
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
teardown(() => {
|
||||
removeCodegenContracts()
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,7 @@
|
||||
import {Action, Name} from '@wharfkit/antelope'
|
||||
import {assert} from 'chai'
|
||||
|
||||
import {ActionDataType, Contract} from 'src/contract'
|
||||
import {Table} from 'src/index-module'
|
||||
import {ActionDataType, Contract, Table} from '@wharfkit/contract'
|
||||
|
||||
// Mocks data for the first action defined in the contract for testing purposes
|
||||
export function getMockParams(contract: Contract): ActionDataType {
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
import {Action, Asset, Bytes, Name, PermissionLevel, Serializer, Struct} from '@wharfkit/antelope'
|
||||
import {makeClient} from '@wharfkit/mock-data'
|
||||
import {assert} from 'chai'
|
||||
|
||||
import RewardsGm from '$test/data/contracts/mock-rewards.gm'
|
||||
import {PlaceholderName, PlaceholderPermission} from '@wharfkit/signing-request'
|
||||
import {Table, TableRowCursor} from 'src/index-module'
|
||||
|
||||
const client = makeClient('https://eos.greymass.com')
|
||||
const contract = new RewardsGm.Contract({client})
|
||||
|
||||
suite('functionality', function () {
|
||||
suite('Contract', function () {
|
||||
suite('retrieve action', function () {
|
||||
test('untyped', function () {
|
||||
const action = contract.action('claim', {
|
||||
account: PlaceholderName,
|
||||
})
|
||||
assert.instanceOf(action, Action)
|
||||
assert.instanceOf(action.account, Name)
|
||||
assert.instanceOf(action.name, Name)
|
||||
assert.instanceOf(action.authorization[0], PermissionLevel)
|
||||
assert.instanceOf(action.data, Bytes)
|
||||
assert.isTrue(action.account.equals('rewards.gm'))
|
||||
assert.isTrue(action.name.equals('claim'))
|
||||
assert.isTrue(action.authorization[0].actor.equals(PlaceholderName))
|
||||
assert.isTrue(action.authorization[0].permission.equals(PlaceholderPermission))
|
||||
|
||||
@Struct.type('claim')
|
||||
class Claim extends Struct {
|
||||
@Struct.field(Name) account!: Name
|
||||
@Struct.field(Asset, {optional: true}) amount?: Asset
|
||||
}
|
||||
const decoded = Serializer.decode({
|
||||
data: action.data,
|
||||
abi: contract.abi,
|
||||
type: Claim,
|
||||
})
|
||||
assert.isTrue(decoded.account.equals(PlaceholderName))
|
||||
assert.isNull(decoded.amount)
|
||||
})
|
||||
test('typed values', function () {
|
||||
const action = contract.action('claim', {
|
||||
account: Name.from('teamgreymass'),
|
||||
})
|
||||
assert.instanceOf(action, Action)
|
||||
})
|
||||
test('struct', function () {
|
||||
@Struct.type('claim')
|
||||
class Claim extends Struct {
|
||||
@Struct.field(Name) account!: Name
|
||||
@Struct.field(Asset, {optional: true}) amount?: Asset
|
||||
}
|
||||
const action = contract.action(
|
||||
'claim',
|
||||
Claim.from({
|
||||
account: Name.from('teamgreymass'),
|
||||
})
|
||||
)
|
||||
assert.instanceOf(action, Action)
|
||||
})
|
||||
})
|
||||
suite('retrieve table', function () {
|
||||
test('automatically typed', async function () {
|
||||
const table = contract.table('config')
|
||||
assert.instanceOf(table, Table)
|
||||
|
||||
const config = await table.get()
|
||||
assert.instanceOf(config, RewardsGm.Types.Config)
|
||||
|
||||
const cursor = await table.first(1)
|
||||
assert.instanceOf(cursor, TableRowCursor)
|
||||
const result = await cursor.next()
|
||||
assert.instanceOf(result[0], RewardsGm.Types.Config)
|
||||
|
||||
const user = await contract.table('users').get()
|
||||
assert.instanceOf(user, RewardsGm.Types.UserRow)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,34 +0,0 @@
|
||||
import {ABI} from '@wharfkit/session'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import {codegen} from '../../src/codegen'
|
||||
|
||||
export async function generateCodegenContract(contractName: string) {
|
||||
// Read the ABI from a JSON file
|
||||
const abiJson = fs.readFileSync(`test/data/abis/${contractName}.json`, {encoding: 'utf8'})
|
||||
const abi = new ABI(JSON.parse(abiJson))
|
||||
|
||||
// Generate the code
|
||||
const generatedCode = await codegen(contractName, abi)
|
||||
|
||||
const testGeneratedCode = generatedCode.replace('@wharfkit/contract', '../../src/index')
|
||||
|
||||
// Create the tmp directory under the test directory if it does not exist
|
||||
if (!fs.existsSync('test/tmp')) {
|
||||
fs.mkdirSync('test/tmp')
|
||||
}
|
||||
|
||||
// Write the generated code to a file in the tmp directory
|
||||
fs.writeFileSync(path.join('test/tmp', `${contractName}.ts`), testGeneratedCode, {
|
||||
encoding: 'utf8',
|
||||
})
|
||||
|
||||
return {
|
||||
import: await import(`../tmp/${contractName}`),
|
||||
text: generatedCode,
|
||||
}
|
||||
}
|
||||
|
||||
export function removeCodegenContracts() {
|
||||
fs.rmSync('test/tmp', {recursive: true, force: true})
|
||||
}
|
||||
Reference in New Issue
Block a user