Skip to content

Commit

Permalink
Merge pull request #110 from API-market/master
Browse files Browse the repository at this point in the history
Merge EOS - support no resources for create account
  • Loading branch information
traylewin authored Jan 12, 2022
2 parents 646cd6b + 29f8f68 commit 12286b4
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 67 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@open-rights-exchange/chainjs",
"version": "3.4.0",
"version": "3.4.1",
"description": "Javascript helper library providing plug-in interfaces to multiple block chains.",
"main": "./dist/index.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getFirstAuthorizationIfOnlyOneExists,
toEosEntityNameOrNull,
toEosPublicKeyOrNull,
EosAssetHelper,
} from '../../../helpers'

const actionName = 'newaccount'
Expand All @@ -38,76 +39,87 @@ export const composeAction = ({
stakeNetQuantity,
stakeCpuQuantity,
transfer,
}: CreateAccountNativeParams): EosActionStruct[] => [
{
account: toEosEntityName('eosio'),
name: actionName,
authorization: [
{
actor: creatorAccountName,
permission: creatorPermission,
},
],
data: {
creator: creatorAccountName,
name: accountName,
owner: {
threshold: 1,
keys: [
{
key: publicKeyOwner,
weight: 1,
},
],
accounts: Array<any>(),
waits: Array<any>(),
},
active: {
threshold: 1,
keys: [
{
key: publicKeyActive,
weight: 1,
},
],
accounts: Array<any>(),
waits: Array<any>(),
}: CreateAccountNativeParams): EosActionStruct[] => {
const actions: EosActionStruct[] = [
{
account: toEosEntityName('eosio'),
name: actionName,
authorization: [
{
actor: creatorAccountName,
permission: creatorPermission,
},
],
data: {
creator: creatorAccountName,
name: accountName,
owner: {
threshold: 1,
keys: [
{
key: publicKeyOwner,
weight: 1,
},
],
accounts: Array<any>(),
waits: Array<any>(),
},
active: {
threshold: 1,
keys: [
{
key: publicKeyActive,
weight: 1,
},
],
accounts: Array<any>(),
waits: Array<any>(),
},
},
},
},
{
account: toEosEntityName('eosio'),
name: 'buyrambytes',
authorization: [
{
actor: creatorAccountName,
permission: creatorPermission,
{
account: toEosEntityName('eosio'),
name: 'buyrambytes',
authorization: [
{
actor: creatorAccountName,
permission: creatorPermission,
},
],
data: {
payer: creatorAccountName,
receiver: accountName,
bytes: ramBytes,
},
],
data: {
payer: creatorAccountName,
receiver: accountName,
bytes: ramBytes,
},
},
{
account: toEosEntityName('eosio'),
name: 'delegatebw',
authorization: [
{
actor: creatorAccountName,
permission: creatorPermission,
]

// add delegatebw action to stake resources (if non-zero)
const { amount: netAmount } = new EosAssetHelper(null, null, stakeNetQuantity)
const { amount: cpuAmount } = new EosAssetHelper(null, null, stakeCpuQuantity)
if (parseFloat(netAmount) !== 0 || parseFloat(cpuAmount) !== 0) {
// Note: Float won't handle high precision numbers (which shouldnt be a problem with EOS)
actions.push({
account: toEosEntityName('eosio'),
name: 'delegatebw',
authorization: [
{
actor: creatorAccountName,
permission: creatorPermission,
},
],
data: {
from: creatorAccountName,
receiver: accountName,
stake_net_quantity: stakeNetQuantity,
stake_cpu_quantity: stakeCpuQuantity,
transfer,
},
],
data: {
from: creatorAccountName,
receiver: accountName,
stake_net_quantity: stakeNetQuantity,
stake_cpu_quantity: stakeCpuQuantity,
transfer,
},
},
]
})
}

return actions
}

export const decomposeAction = (action: EosActionStruct): EosDecomposeReturn => {
const { name, data, authorization } = action
Expand Down

0 comments on commit 12286b4

Please sign in to comment.