Skip to content

Commit

Permalink
fix: handling use of SymbolCode properly
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Feb 27, 2024
1 parent bccdcf9 commit c09ad6a
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test_generate: node_modules clean lib
update_mock_contracts: node_modules clean lib
node lib/cli.js generate atomicassets -u https://jungle4.greymass.com -j test/data/abis/atomicassets.json -f test/data/contracts/mock-atomicassets.ts -e .eslintrc
node lib/cli.js generate boid -u https://jungle4.greymass.com -j test/data/abis/boid.json -f test/data/contracts/mock-boid.ts -e .eslintrc
node lib/cli.js generate payroll.boid -u https://telos.api.animus.is -j test/data/abis/payroll.boid.json -f test/data/contracts/mock-payroll.boid.ts -e .eslintrc
node lib/cli.js generate eosio -u https://jungle4.greymass.com -j test/data/abis/eosio.json -f test/data/contracts/mock-eosio.ts -e .eslintrc
node lib/cli.js generate eosio.msig -u https://jungle4.greymass.com -j test/data/abis/eosio.msig.json -f test/data/contracts/mock-eosio.msig.ts -e .eslintrc
node lib/cli.js generate eosio.token -u https://jungle4.greymass.com -j test/data/abis/eosio.token.json -f test/data/contracts/mock-eosio.token.ts -e .eslintrc
Expand Down
2 changes: 1 addition & 1 deletion src/commands/contract/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function structIsUsedInActionParams(struct: ABI.Struct, abi: ABI.Def) {
}

export function findCoreClassImport(type: string) {
if (type === 'symbol') {
if (type === 'symbol' || type === 'symbol_code') {
return 'Asset'
}

Expand Down
8 changes: 8 additions & 0 deletions src/commands/contract/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ export function generateActionsNamespace(abi: ABI.Def): ts.ModuleDeclaration {
function findParamTypeString(typeString: string, namespace = '', abi: ABI.Def): string {
const fieldType = findExternalType(typeString, namespace, abi)

if (fieldType === 'Symbol_code') {
return 'Asset.SymbolCodeType'
}

if (fieldType === 'Symbol_code[]') {
return 'Asset.SymbolCodeType[]'
}

if (fieldType === 'Symbol') {
return 'Asset.SymbolType'
}
Expand Down
4 changes: 4 additions & 0 deletions src/commands/contract/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ export function findFieldTypeString(
return 'Asset.Symbol'
}

if (fieldType === 'Symbol_code') {
return 'Asset.SymbolCode'
}

return parseType(fieldType)
}

Expand Down
245 changes: 245 additions & 0 deletions test/data/abis/payroll.boid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
{
"version": "eosio::abi/1.2",
"types": [],
"structs": [
{
"name": "Payroll",
"base": "",
"fields": [
{
"name": "id",
"type": "uint64"
},
{
"name": "total",
"type": "asset"
},
{
"name": "paid",
"type": "asset"
},
{
"name": "startTime",
"type": "time_point_sec"
},
{
"name": "finishTime",
"type": "time_point_sec"
},
{
"name": "lastPayout",
"type": "time_point_sec"
},
{
"name": "minClaimFrequencySec",
"type": "uint32"
},
{
"name": "receiverAccount",
"type": "name"
},
{
"name": "treasuryAccount",
"type": "name"
},
{
"name": "paused",
"type": "bool"
},
{
"name": "meta",
"type": "bytes"
}
]
},
{
"name": "PayrollConfig",
"base": "",
"fields": [
{
"name": "total",
"type": "asset"
},
{
"name": "startTime",
"type": "time_point_sec"
},
{
"name": "finishTime",
"type": "time_point_sec"
},
{
"name": "minClaimFrequencySec",
"type": "uint32"
},
{
"name": "receiverAccount",
"type": "name"
},
{
"name": "treasuryAccount",
"type": "name"
},
{
"name": "meta",
"type": "bytes"
},
{
"name": "paused",
"type": "bool"
}
]
},
{
"name": "TokensWhitelist",
"base": "",
"fields": [
{
"name": "sym",
"type": "symbol"
},
{
"name": "contract",
"type": "name"
}
]
},
{
"name": "payroll.add",
"base": "",
"fields": [
{
"name": "payrollConfig",
"type": "PayrollConfig"
}
]
},
{
"name": "payroll.edit",
"base": "",
"fields": [
{
"name": "payrollId",
"type": "uint64"
},
{
"name": "pause",
"type": "bool"
},
{
"name": "minClaimFrequencySec",
"type": "uint32"
},
{
"name": "receiverAccount",
"type": "name"
},
{
"name": "treasuryAccount",
"type": "name"
},
{
"name": "meta",
"type": "bytes"
}
]
},
{
"name": "payroll.pay",
"base": "",
"fields": [
{
"name": "payrollId",
"type": "uint64"
}
]
},
{
"name": "payroll.rm",
"base": "",
"fields": [
{
"name": "payrollId",
"type": "uint64"
}
]
},
{
"name": "tokenwl.add",
"base": "",
"fields": [
{
"name": "sym",
"type": "symbol"
},
{
"name": "contract",
"type": "name"
}
]
},
{
"name": "tokenwl.rm",
"base": "",
"fields": [
{
"name": "sym",
"type": "symbol_code"
}
]
}
],
"actions": [
{
"name": "payroll.add",
"type": "payroll.add",
"ricardian_contract": ""
},
{
"name": "payroll.edit",
"type": "payroll.edit",
"ricardian_contract": ""
},
{
"name": "payroll.pay",
"type": "payroll.pay",
"ricardian_contract": ""
},
{
"name": "payroll.rm",
"type": "payroll.rm",
"ricardian_contract": ""
},
{
"name": "tokenwl.add",
"type": "tokenwl.add",
"ricardian_contract": ""
},
{
"name": "tokenwl.rm",
"type": "tokenwl.rm",
"ricardian_contract": ""
}
],
"tables": [
{
"name": "payrolls",
"index_type": "i64",
"key_names": [],
"key_types": [],
"type": "Payroll"
},
{
"name": "tokenwl",
"index_type": "i64",
"key_names": [],
"key_types": [],
"type": "TokensWhitelist"
}
],
"ricardian_clauses": [],
"error_messages": [],
"abi_extensions": [],
"variants": [],
"action_results": []
}
Loading

0 comments on commit c09ad6a

Please sign in to comment.