Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge get_producer_schedule into new APIs branch #58

Merged
merged 5 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/api/v1/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Name,
NameType,
PackedTransaction,
PublicKeyType,
SignedTransaction,
SignedTransactionType,
UInt128,
Expand All @@ -20,10 +21,14 @@ import {

import {
AccountObject,
AccountsByAuthorizers,
GetAbiResponse,
GetBlockHeaderStateResponse,
GetBlockResponse,
GetInfoResponse,
GetProducerScheduleResponse,
GetProtocolFeaturesParams,
GetProtocolFeaturesResponse,
GetTableByScopeParams,
GetTableByScopeResponse,
GetTableRowsParams,
Expand Down Expand Up @@ -60,6 +65,22 @@ export class ChainAPI {
})
}

async get_accounts_by_authorizers(keys: PublicKeyType[]) {
return this.client.call({
path: '/v1/chain/get_accounts_by_authorizers',
params: {keys: keys},
responseType: AccountsByAuthorizers,
})
}

async get_activated_protocol_features(params?: GetProtocolFeaturesParams) {
return this.client.call({
path: '/v1/chain/get_activated_protocol_features',
params,
responseType: GetProtocolFeaturesResponse,
})
}

async get_block(block_num_or_id: Checksum256Type | UInt32Type) {
return this.client.call({
path: '/v1/chain/get_block',
Expand Down Expand Up @@ -98,6 +119,13 @@ export class ChainAPI {
})
}

async get_producer_schedule() {
return this.client.call({
path: '/v1/chain/get_producer_schedule',
responseType: GetProducerScheduleResponse,
})
}

async compute_transaction(tx: SignedTransactionType | PackedTransaction) {
if (!isInstanceOf(tx, PackedTransaction)) {
tx = PackedTransaction.fromSigned(SignedTransaction.from(tx))
Expand Down
82 changes: 82 additions & 0 deletions src/api/v1/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Float64,
Int32,
Int64,
KeyWeight,
Name,
NameType,
PublicKey,
Expand All @@ -26,6 +27,7 @@ import {
UInt32,
UInt32Type,
UInt64,
Weight,
} from '../../chain'

import {ABISerializableObject, ABISerializableType, Serializer} from '../../serializer'
Expand Down Expand Up @@ -157,6 +159,21 @@ export class AccountObject extends Struct {
}
}

@Struct.type('account_by_authorizers_row')
export class AccountByAuthorizersRow extends Struct {
@Struct.field(Name) declare account_name: Name
@Struct.field(Name) declare permission_name: Name
@Struct.field(PublicKey) declare authorizing_key: PublicKey
@Struct.field(Weight) declare weight: Weight
@Struct.field(UInt32) declare threshold: UInt32
}

@Struct.type('account_by_authorizers')
export class AccountsByAuthorizers extends Struct {
@Struct.field(AccountByAuthorizersRow, {array: true})
declare accounts: AccountByAuthorizersRow[]
}

@Struct.type('new_producers_entry')
export class NewProducersEntry extends Struct {
@Struct.field('name') declare producer_name: Name
Expand Down Expand Up @@ -591,3 +608,68 @@ export class GetTransactionStatusResponse extends Struct {
@Struct.field('checksum256') declare earliest_tracked_block_id: Checksum256
@Struct.field('uint32') declare earliest_tracked_block_number: UInt32
}

@Struct.type('producer_authority')
export class ProducerAuthority extends Struct {
@Struct.field(UInt32) threshold!: UInt32
@Struct.field(KeyWeight, {array: true}) keys!: KeyWeight[]
}

export type ProducerEntry = [number, ProducerAuthority]

@Struct.type('producer')
export class Producer extends Struct {
@Struct.field('name') declare producer_name: Name
@Struct.field('any', {array: true}) declare authority: ProducerEntry

static from(data: any) {
return new this({
...data,
authority: [data.authority[0], ProducerAuthority.from(data.authority[1])],
})
}
}

@Struct.type('producer_schedule')
export class ProducerSchedule extends Struct {
@Struct.field('uint32') declare version: UInt32
@Struct.field(Producer, {array: true}) declare producers: Producer[]
}

@Struct.type('get_producer_schedule_response')
export class GetProducerScheduleResponse extends Struct {
@Struct.field(ProducerSchedule, {optional: true}) declare active: ProducerSchedule
@Struct.field(ProducerSchedule, {optional: true}) declare pending: ProducerSchedule
@Struct.field(ProducerSchedule, {optional: true}) declare proposed: ProducerSchedule
}

@Struct.type('protocol_feature')
export class ProtocolFeature extends Struct {
@Struct.field('checksum256') declare feature_digest: Checksum256
@Struct.field('uint32') declare activation_ordinal: UInt32
@Struct.field('uint32') declare activation_block_num: UInt32
@Struct.field('checksum256') declare description_digest: Checksum256
@Struct.field('string', {array: true}) declare dependencies: string[]
@Struct.field('string') declare protocol_feature_type: string
@Struct.field('any', {array: true}) declare specification: any[]
}

@Struct.type('get_protocol_features_response')
export class GetProtocolFeaturesResponse extends Struct {
@Struct.field(ProtocolFeature, {array: true})
declare activated_protocol_features: ProtocolFeature[]
@Struct.field('uint32', {optional: true}) declare more: UInt32
}

export interface GetProtocolFeaturesParams {
/** Lower lookup bound. */
lower_bound?: UInt32 | number
/** Upper lookup bound. */
upper_bound?: UInt32 | number
/** How many rows to fetch, defaults to 10 if unset. */
limit?: UInt32Type
/** Flag to indicate it is has to search by block number */
search_by_block_num?: boolean
/** Whether to iterate records in reverse order. */
reverse?: boolean
}
55 changes: 55 additions & 0 deletions test/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,45 @@ suite('api v1', function () {
assert.isTrue(permission.linked_actions[0].action.equals('transfer'))
})

test('chain get_accounts_by_authorizers', async function () {
const response = await jungle4.v1.chain.get_accounts_by_authorizers([
'PUB_K1_6RWZ1CmDL4B6LdixuertnzxcRuUDac3NQspJEvMnebGcXY4zZj',
])
assert.lengthOf(response.accounts, 5)
assert.isTrue(response.accounts[0].account_name.equals('testtestasdf'))
assert.isTrue(response.accounts[0].permission_name.equals('owner'))
assert.isTrue(
response.accounts[0].authorizing_key.equals(
'PUB_K1_6RWZ1CmDL4B6LdixuertnzxcRuUDac3NQspJEvMnebGcXY4zZj'
)
)
assert.isTrue(response.accounts[0].weight.equals(1))
assert.isTrue(response.accounts[0].threshold.equals(1))
})

test('chain get_activated_protocol_features', async function () {
const response = await jungle4.v1.chain.get_activated_protocol_features()
assert.lengthOf(response.activated_protocol_features, 10)
assert.isTrue(response.more.equals(10))
const [feature] = response.activated_protocol_features
assert.isTrue(
feature.feature_digest.equals(
'0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd'
)
)
assert.isTrue(feature.activation_ordinal.equals(0))
assert.isTrue(feature.activation_block_num.equals(4))
assert.isTrue(
feature.description_digest.equals(
'64fe7df32e9b86be2b296b3f81dfd527f84e82b98e363bc97e40bc7a83733310'
)
)
assert.isArray(feature.dependencies)
assert.lengthOf(feature.dependencies, 0)
assert.equal(feature.protocol_feature_type, 'builtin')
assert.isArray(feature.specification)
})

test('chain get_block (by id)', async function () {
const block = await eos.v1.chain.get_block(
'00816d41e41f1462acb648b810b20f152d944fabd79aaff31c9f50102e4e5db9'
Expand Down Expand Up @@ -193,6 +232,22 @@ suite('api v1', function () {
)
})

test('chain get_producer_schedule', async function () {
const schedule = await jungle.v1.chain.get_producer_schedule()
assert.isTrue(schedule.active.version.equals(108))
assert.lengthOf(schedule.active.producers, 21)
assert.isTrue(schedule.active.producers[0].producer_name.equals('alohaeostest'))
assert.lengthOf(schedule.active.producers[0].authority, 2)
assert.isTrue(schedule.active.producers[0].authority[1].threshold.equals(1))
assert.lengthOf(schedule.active.producers[0].authority[1].keys, 1)
assert.isTrue(schedule.active.producers[0].authority[1].keys[0].weight.equals(1))
assert.isTrue(
schedule.active.producers[0].authority[1].keys[0].key.equals(
'PUB_K1_8JTznQrfvYcoFskidgKeKsmPsx3JBMpTo1jsEG2y1Ho6oGNCgf'
)
)
})

test('chain push_transaction', async function () {
@Struct.type('transfer')
class Transfer extends Struct {
Expand Down
161 changes: 161 additions & 0 deletions test/data/15cd04ae0e6232dabb0c9946f99ccb2b2be6393f.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"headers": {
"access-control-allow-headers": "Origin, X-Requested-With, Content-Type, Accept",
"access-control-allow-methods": "GET, POST, HEAD, OPTIONS",
"access-control-allow-origin": "*",
"connection": "close",
"content-length": "3729",
"content-type": "application/json",
"date": "Sun, 16 Apr 2023 21:09:20 GMT",
"server": "nginx/1.24.0"
},
"status": 200,
"json": {
"activated_protocol_features": [
{
"feature_digest": "0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd",
"activation_ordinal": 0,
"activation_block_num": 4,
"description_digest": "64fe7df32e9b86be2b296b3f81dfd527f84e82b98e363bc97e40bc7a83733310",
"dependencies": [],
"protocol_feature_type": "builtin",
"specification": [
{
"name": "builtin_feature_codename",
"value": "PREACTIVATE_FEATURE"
}
]
},
{
"feature_digest": "f0af56d2c5a48d60a4a5b5c903edfb7db3a736a94ed589d0b797df33ff9d3e1d",
"activation_ordinal": 1,
"activation_block_num": 12,
"description_digest": "1eab748b95a2e6f4d7cb42065bdee5566af8efddf01a55a0a8d831b823f8828a",
"dependencies": [],
"protocol_feature_type": "builtin",
"specification": [
{
"name": "builtin_feature_codename",
"value": "GET_SENDER"
}
]
},
{
"feature_digest": "2652f5f96006294109b3dd0bbde63693f55324af452b799ee137a81a905eed25",
"activation_ordinal": 2,
"activation_block_num": 12,
"description_digest": "898082c59f921d0042e581f00a59d5ceb8be6f1d9c7a45b6f07c0e26eaee0222",
"dependencies": [],
"protocol_feature_type": "builtin",
"specification": [
{
"name": "builtin_feature_codename",
"value": "FORWARD_SETCODE"
}
]
},
{
"feature_digest": "8ba52fe7a3956c5cd3a656a3174b931d3bb2abb45578befc59f283ecd816a405",
"activation_ordinal": 3,
"activation_block_num": 12,
"description_digest": "2f1f13e291c79da5a2bbad259ed7c1f2d34f697ea460b14b565ac33b063b73e2",
"dependencies": [],
"protocol_feature_type": "builtin",
"specification": [
{
"name": "builtin_feature_codename",
"value": "ONLY_BILL_FIRST_AUTHORIZER"
}
]
},
{
"feature_digest": "ad9e3d8f650687709fd68f4b90b41f7d825a365b02c23a636cef88ac2ac00c43",
"activation_ordinal": 4,
"activation_block_num": 12,
"description_digest": "e71b6712188391994c78d8c722c1d42c477cf091e5601b5cf1befd05721a57f3",
"dependencies": [],
"protocol_feature_type": "builtin",
"specification": [
{
"name": "builtin_feature_codename",
"value": "RESTRICT_ACTION_TO_SELF"
}
]
},
{
"feature_digest": "68dcaa34c0517d19666e6b33add67351d8c5f69e999ca1e37931bc410a297428",
"activation_ordinal": 5,
"activation_block_num": 12,
"description_digest": "2853617cec3eabd41881eb48882e6fc5e81a0db917d375057864b3befbe29acd",
"dependencies": [],
"protocol_feature_type": "builtin",
"specification": [
{
"name": "builtin_feature_codename",
"value": "DISALLOW_EMPTY_PRODUCER_SCHEDULE"
}
]
},
{
"feature_digest": "e0fb64b1085cc5538970158d05a009c24e276fb94e1a0bf6a528b48fbc4ff526",
"activation_ordinal": 6,
"activation_block_num": 12,
"description_digest": "a98241c83511dc86c857221b9372b4aa7cea3aaebc567a48604e1d3db3557050",
"dependencies": [],
"protocol_feature_type": "builtin",
"specification": [
{
"name": "builtin_feature_codename",
"value": "FIX_LINKAUTH_RESTRICTION"
}
]
},
{
"feature_digest": "ef43112c6543b88db2283a2e077278c315ae2c84719a8b25f25cc88565fbea99",
"activation_ordinal": 7,
"activation_block_num": 12,
"description_digest": "9908b3f8413c8474ab2a6be149d3f4f6d0421d37886033f27d4759c47a26d944",
"dependencies": [],
"protocol_feature_type": "builtin",
"specification": [
{
"name": "builtin_feature_codename",
"value": "REPLACE_DEFERRED"
}
]
},
{
"feature_digest": "4a90c00d55454dc5b059055ca213579c6ea856967712a56017487886a4d4cc0f",
"activation_ordinal": 8,
"activation_block_num": 12,
"description_digest": "45967387ee92da70171efd9fefd1ca8061b5efe6f124d269cd2468b47f1575a0",
"dependencies": [
"ef43112c6543b88db2283a2e077278c315ae2c84719a8b25f25cc88565fbea99"
],
"protocol_feature_type": "builtin",
"specification": [
{
"name": "builtin_feature_codename",
"value": "NO_DUPLICATE_DEFERRED_ID"
}
]
},
{
"feature_digest": "1a99a59d87e06e09ec5b028a9cbb7749b4a5ad8819004365d02dc4379a8b7241",
"activation_ordinal": 9,
"activation_block_num": 12,
"description_digest": "f3c3d91c4603cde2397268bfed4e662465293aab10cd9416db0d442b8cec2949",
"dependencies": [],
"protocol_feature_type": "builtin",
"specification": [
{
"name": "builtin_feature_codename",
"value": "ONLY_LINK_TO_EXISTING_PERMISSION"
}
]
}
],
"more": 10
},
"text": "{\"activated_protocol_features\":[{\"feature_digest\":\"0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd\",\"activation_ordinal\":0,\"activation_block_num\":4,\"description_digest\":\"64fe7df32e9b86be2b296b3f81dfd527f84e82b98e363bc97e40bc7a83733310\",\"dependencies\":[],\"protocol_feature_type\":\"builtin\",\"specification\":[{\"name\":\"builtin_feature_codename\",\"value\":\"PREACTIVATE_FEATURE\"}]},{\"feature_digest\":\"f0af56d2c5a48d60a4a5b5c903edfb7db3a736a94ed589d0b797df33ff9d3e1d\",\"activation_ordinal\":1,\"activation_block_num\":12,\"description_digest\":\"1eab748b95a2e6f4d7cb42065bdee5566af8efddf01a55a0a8d831b823f8828a\",\"dependencies\":[],\"protocol_feature_type\":\"builtin\",\"specification\":[{\"name\":\"builtin_feature_codename\",\"value\":\"GET_SENDER\"}]},{\"feature_digest\":\"2652f5f96006294109b3dd0bbde63693f55324af452b799ee137a81a905eed25\",\"activation_ordinal\":2,\"activation_block_num\":12,\"description_digest\":\"898082c59f921d0042e581f00a59d5ceb8be6f1d9c7a45b6f07c0e26eaee0222\",\"dependencies\":[],\"protocol_feature_type\":\"builtin\",\"specification\":[{\"name\":\"builtin_feature_codename\",\"value\":\"FORWARD_SETCODE\"}]},{\"feature_digest\":\"8ba52fe7a3956c5cd3a656a3174b931d3bb2abb45578befc59f283ecd816a405\",\"activation_ordinal\":3,\"activation_block_num\":12,\"description_digest\":\"2f1f13e291c79da5a2bbad259ed7c1f2d34f697ea460b14b565ac33b063b73e2\",\"dependencies\":[],\"protocol_feature_type\":\"builtin\",\"specification\":[{\"name\":\"builtin_feature_codename\",\"value\":\"ONLY_BILL_FIRST_AUTHORIZER\"}]},{\"feature_digest\":\"ad9e3d8f650687709fd68f4b90b41f7d825a365b02c23a636cef88ac2ac00c43\",\"activation_ordinal\":4,\"activation_block_num\":12,\"description_digest\":\"e71b6712188391994c78d8c722c1d42c477cf091e5601b5cf1befd05721a57f3\",\"dependencies\":[],\"protocol_feature_type\":\"builtin\",\"specification\":[{\"name\":\"builtin_feature_codename\",\"value\":\"RESTRICT_ACTION_TO_SELF\"}]},{\"feature_digest\":\"68dcaa34c0517d19666e6b33add67351d8c5f69e999ca1e37931bc410a297428\",\"activation_ordinal\":5,\"activation_block_num\":12,\"description_digest\":\"2853617cec3eabd41881eb48882e6fc5e81a0db917d375057864b3befbe29acd\",\"dependencies\":[],\"protocol_feature_type\":\"builtin\",\"specification\":[{\"name\":\"builtin_feature_codename\",\"value\":\"DISALLOW_EMPTY_PRODUCER_SCHEDULE\"}]},{\"feature_digest\":\"e0fb64b1085cc5538970158d05a009c24e276fb94e1a0bf6a528b48fbc4ff526\",\"activation_ordinal\":6,\"activation_block_num\":12,\"description_digest\":\"a98241c83511dc86c857221b9372b4aa7cea3aaebc567a48604e1d3db3557050\",\"dependencies\":[],\"protocol_feature_type\":\"builtin\",\"specification\":[{\"name\":\"builtin_feature_codename\",\"value\":\"FIX_LINKAUTH_RESTRICTION\"}]},{\"feature_digest\":\"ef43112c6543b88db2283a2e077278c315ae2c84719a8b25f25cc88565fbea99\",\"activation_ordinal\":7,\"activation_block_num\":12,\"description_digest\":\"9908b3f8413c8474ab2a6be149d3f4f6d0421d37886033f27d4759c47a26d944\",\"dependencies\":[],\"protocol_feature_type\":\"builtin\",\"specification\":[{\"name\":\"builtin_feature_codename\",\"value\":\"REPLACE_DEFERRED\"}]},{\"feature_digest\":\"4a90c00d55454dc5b059055ca213579c6ea856967712a56017487886a4d4cc0f\",\"activation_ordinal\":8,\"activation_block_num\":12,\"description_digest\":\"45967387ee92da70171efd9fefd1ca8061b5efe6f124d269cd2468b47f1575a0\",\"dependencies\":[\"ef43112c6543b88db2283a2e077278c315ae2c84719a8b25f25cc88565fbea99\"],\"protocol_feature_type\":\"builtin\",\"specification\":[{\"name\":\"builtin_feature_codename\",\"value\":\"NO_DUPLICATE_DEFERRED_ID\"}]},{\"feature_digest\":\"1a99a59d87e06e09ec5b028a9cbb7749b4a5ad8819004365d02dc4379a8b7241\",\"activation_ordinal\":9,\"activation_block_num\":12,\"description_digest\":\"f3c3d91c4603cde2397268bfed4e662465293aab10cd9416db0d442b8cec2949\",\"dependencies\":[],\"protocol_feature_type\":\"builtin\",\"specification\":[{\"name\":\"builtin_feature_codename\",\"value\":\"ONLY_LINK_TO_EXISTING_PERMISSION\"}]}],\"more\":10}"
}
Loading