Skip to content

Commit 2d7970e

Browse files
authored
refactor!: support of wip rc.2 (nfts, empty blocks, config endpoints) (#251)
1 parent 77b7f11 commit 2d7970e

File tree

22 files changed

+472
-225
lines changed

22 files changed

+472
-225
lines changed

.github/workflows/pull-request.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
branches: [main]
77
env:
88
IROHA_GIT: https://github.com/hyperledger-iroha/iroha.git
9-
IROHA_REV: daa2d50fbe288aed1231c6f45c853698435477d6
9+
IROHA_REV: c1d8b5e2fbffabba13e448a66f9b5dd86875cf18 # 2.0.0-rc.2 wip
1010
jobs:
1111
prep-crypto-wasm:
1212
runs-on: ubuntu-latest
@@ -62,7 +62,6 @@ jobs:
6262
if: steps.prep-cache.outputs.cache-hit != 'true'
6363
run: |
6464
deno task prep:iroha --git $IROHA_GIT --git-rev $IROHA_REV
65-
deno task prep:iroha:build
6665
6766
check-only:
6867
if: github.event_name == 'pull_request'

deno.lock

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

etc/__snapshots__/codegen_test.ts.snap

+94-24
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ snapshot[`generate prototypes > prototypes snapshot 1`] = `
66
export type QueryCompatibleSelectors = {
77
FindDomains: 'domain' | 'domain-id' | 'domain-id-name' | 'domain-metadata' | 'domain-metadata-key'
88
FindAccounts: 'account' | 'account-id' | 'account-id-domain' | 'account-id-domain-name' | 'account-id-signatory' | 'account-metadata' | 'account-metadata-key'
9-
FindAssets: 'asset' | 'asset-id' | 'asset-id-account' | 'asset-id-account-domain' | 'asset-id-account-domain-name' | 'asset-id-account-signatory' | 'asset-id-definition' | 'asset-id-definition-domain' | 'asset-id-definition-domain-name' | 'asset-id-definition-name' | 'asset-value' | 'asset-value-numeric' | 'asset-value-store' | 'asset-value-store-key'
9+
FindAssets: 'asset' | 'asset-id' | 'asset-id-account' | 'asset-id-account-domain' | 'asset-id-account-domain-name' | 'asset-id-account-signatory' | 'asset-id-definition' | 'asset-id-definition-domain' | 'asset-id-definition-domain-name' | 'asset-id-definition-name' | 'asset-value'
1010
FindAssetsDefinitions: 'asset-definition' | 'asset-definition-id' | 'asset-definition-id-domain' | 'asset-definition-id-domain-name' | 'asset-definition-id-name' | 'asset-definition-metadata' | 'asset-definition-metadata-key'
11+
FindNfts: 'nft' | 'nft-id' | 'nft-id-domain' | 'nft-id-domain-name' | 'nft-id-name' | 'nft-metadata' | 'nft-metadata-key' | 'nft-account-id' | 'nft-account-id-domain' | 'nft-account-id-domain-name' | 'nft-account-id-signatory'
1112
FindRoles: 'role' | 'role-id' | 'role-id-name'
1213
FindRoleIds: 'role-id' | 'role-id-name'
1314
FindPermissionsByAccountId: 'permission'
@@ -44,17 +45,25 @@ export type SelectorIdToOutput = {
4445
'asset-id-definition-domain': lib.DomainId
4546
'asset-id-definition-domain-name': lib.Name
4647
'asset-id-definition-name': lib.Name
47-
'asset-value': lib.AssetValue
48-
'asset-value-numeric': lib.Numeric
49-
'asset-value-store': lib.Metadata
50-
'asset-value-store-key': lib.Json
48+
'asset-value': lib.Numeric
5149
'asset-definition': lib.AssetDefinition
5250
'asset-definition-id': lib.AssetDefinitionId
5351
'asset-definition-id-domain': lib.DomainId
5452
'asset-definition-id-domain-name': lib.Name
5553
'asset-definition-id-name': lib.Name
5654
'asset-definition-metadata': lib.Metadata
5755
'asset-definition-metadata-key': lib.Json
56+
'nft': lib.Nft
57+
'nft-id': lib.NftId
58+
'nft-id-domain': lib.DomainId
59+
'nft-id-domain-name': lib.Name
60+
'nft-id-name': lib.Name
61+
'nft-metadata': lib.Metadata
62+
'nft-metadata-key': lib.Json
63+
'nft-account-id': lib.AccountId
64+
'nft-account-id-domain': lib.DomainId
65+
'nft-account-id-domain-name': lib.Name
66+
'nft-account-id-signatory': lib.PublicKey
5867
'role': lib.Role
5968
'role-id': lib.RoleId
6069
'role-id-name': lib.Name
@@ -151,15 +160,6 @@ export type QuerySelectors = {
151160
}
152161
value: {
153162
__selector: 'asset-value',
154-
numeric: {
155-
__selector: 'asset-value-numeric',
156-
}
157-
store: {
158-
__selector: 'asset-value-store',
159-
key(key: lib.Name): {
160-
__selector: 'asset-value-store-key',
161-
}
162-
}
163163
}
164164
}
165165
FindAssetsDefinitions: {
@@ -183,6 +183,39 @@ export type QuerySelectors = {
183183
}
184184
}
185185
}
186+
FindNfts: {
187+
__selector: 'nft',
188+
id: {
189+
__selector: 'nft-id',
190+
domain: {
191+
__selector: 'nft-id-domain',
192+
name: {
193+
__selector: 'nft-id-domain-name',
194+
}
195+
}
196+
name: {
197+
__selector: 'nft-id-name',
198+
}
199+
}
200+
metadata: {
201+
__selector: 'nft-metadata',
202+
key(key: lib.Name): {
203+
__selector: 'nft-metadata-key',
204+
}
205+
}
206+
accountId: {
207+
__selector: 'nft-account-id',
208+
domain: {
209+
__selector: 'nft-account-id-domain',
210+
name: {
211+
__selector: 'nft-account-id-domain-name',
212+
}
213+
}
214+
signatory: {
215+
__selector: 'nft-account-id-signatory',
216+
}
217+
}
218+
}
186219
FindRoles: {
187220
__selector: 'role',
188221
id: {
@@ -378,16 +411,7 @@ export type QueryPredicates = {
378411
}
379412
}
380413
}
381-
value: {
382-
isNumeric: () => lib.AssetProjectionPredicate
383-
isStore: () => lib.AssetProjectionPredicate
384-
numeric: never
385-
store: {
386-
key: (key: lib.Name) => {
387-
equals: (value: lib.Json) => lib.AssetProjectionPredicate
388-
}
389-
}
390-
}
414+
value: never
391415
}
392416
FindAssetsDefinitions: {
393417
id: {
@@ -414,6 +438,46 @@ export type QueryPredicates = {
414438
}
415439
}
416440
}
441+
FindNfts: {
442+
id: {
443+
equals: (value: lib.NftId) => lib.NftProjectionPredicate
444+
domain: {
445+
equals: (value: lib.DomainId) => lib.NftProjectionPredicate
446+
name: {
447+
equals: (value: lib.String) => lib.NftProjectionPredicate
448+
contains: (value: lib.String) => lib.NftProjectionPredicate
449+
startsWith: (value: lib.String) => lib.NftProjectionPredicate
450+
endsWith: (value: lib.String) => lib.NftProjectionPredicate
451+
}
452+
}
453+
name: {
454+
equals: (value: lib.String) => lib.NftProjectionPredicate
455+
contains: (value: lib.String) => lib.NftProjectionPredicate
456+
startsWith: (value: lib.String) => lib.NftProjectionPredicate
457+
endsWith: (value: lib.String) => lib.NftProjectionPredicate
458+
}
459+
}
460+
metadata: {
461+
key: (key: lib.Name) => {
462+
equals: (value: lib.Json) => lib.NftProjectionPredicate
463+
}
464+
}
465+
accountId: {
466+
equals: (value: lib.AccountId) => lib.NftProjectionPredicate
467+
domain: {
468+
equals: (value: lib.DomainId) => lib.NftProjectionPredicate
469+
name: {
470+
equals: (value: lib.String) => lib.NftProjectionPredicate
471+
contains: (value: lib.String) => lib.NftProjectionPredicate
472+
startsWith: (value: lib.String) => lib.NftProjectionPredicate
473+
endsWith: (value: lib.String) => lib.NftProjectionPredicate
474+
}
475+
}
476+
signatory: {
477+
equals: (value: lib.PublicKey) => lib.NftProjectionPredicate
478+
}
479+
}
480+
}
417481
FindRoles: {
418482
id: {
419483
equals: (value: lib.RoleId) => lib.RoleProjectionPredicate
@@ -527,6 +591,7 @@ export type QueryPredicates = {
527591
}
528592
}
529593
FindBlocks: {
594+
isEmpty: () => lib.SignedBlockProjectionPredicate
530595
header: {
531596
hash: {
532597
equals: (value: lib.Hash) => lib.SignedBlockProjectionPredicate
@@ -568,6 +633,11 @@ export class FindAPI {
568633
return new client.QueryBuilder(this._executor, 'FindAssetsDefinitions', params)
569634
}
570635
636+
/** Convenience method for \`FindNfts\` query, a variant of {@linkcode types.QueryBox} enum. */
637+
public nfts(params?: core.QueryBuilderParams): client.QueryBuilder<'FindNfts'> {
638+
return new client.QueryBuilder(this._executor, 'FindNfts', params)
639+
}
640+
571641
/** Convenience method for \`FindRoles\` query, a variant of {@linkcode types.QueryBox} enum. */
572642
public roles(params?: core.QueryBuilderParams): client.QueryBuilder<'FindRoles'> {
573643
return new client.QueryBuilder(this._executor, 'FindRoles', params)

etc/codegen.ts

+29
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,14 @@ export type LibType =
150150
| 'Bool'
151151
| 'Timestamp'
152152
| 'Duration'
153+
| 'DurationCompact'
153154
| 'Name'
154155
| 'CompoundPredicate'
155156
| 'DomainId'
156157
| `AccountId`
157158
| `AssetDefinitionId`
158159
| `AssetId`
160+
| 'NftId'
159161
| 'Algorithm'
160162
| 'Signature'
161163
| 'Hash'
@@ -250,6 +252,7 @@ export class Resolver {
250252
'DomainId',
251253
'AccountId',
252254
'AssetId',
255+
'NftId',
253256
'AssetDefinitionId',
254257
'Compact',
255258
'Algorithm',
@@ -279,6 +282,21 @@ export class Resolver {
279282
}),
280283
}),
281284
)
285+
.with(
286+
{ refStr: 'Uptime', schema: { Tuple: ['Compact<u64>', 'u32'] } },
287+
({ refStr }) => ({
288+
t: 'local',
289+
id: refStr,
290+
// TODO: merge with duration? change Status in schema?
291+
emit: () => ({
292+
t: 'struct',
293+
fields: [{ name: 'secs', type: { t: 'lib', id: 'Compact' } }, {
294+
name: 'nanos',
295+
type: { t: 'lib', id: 'U32' },
296+
}],
297+
}),
298+
}),
299+
)
282300
.with(
283301
{
284302
ref: { id: P.union('Register', 'Unregister'), items: [P._] },
@@ -721,7 +739,18 @@ export class Resolver {
721739
params: [{ t: 'lib', id: 'NonZero', params: [{ t: 'lib', id: rewriteWith }] }],
722740
}),
723741
)
742+
.with(
743+
[
744+
'Duration',
745+
{ t: 'lib', id: 'Compact' },
746+
],
747+
() => ({
748+
t: 'lib',
749+
id: 'DurationCompact',
750+
}),
751+
)
724752
.otherwise(() => {
753+
console.debug(this.resolve(x.type))
725754
throw new Error(`Unexpected type of a field with _ms suffix: ${x.type}`)
726755
})
727756
return { name: x.name.slice(0, -3), type }

etc/iroha-build-utils.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ const resolvePrepIroha = (...paths: string[]) => {
1717
return path.resolve(dirname, '../prep/iroha', ...paths)
1818
}
1919

20-
export type Binary = 'irohad' | 'kagami' | 'iroha_codec'
20+
export type Binary = 'irohad' | 'kagami'
2121

2222
export const BIN_PATHS: Record<Binary, string> = {
2323
irohad: resolvePrepIroha('irohad'),
2424
kagami: resolvePrepIroha('kagami'),
25-
iroha_codec: resolvePrepIroha('iroha_codec'),
2625
}
2726

2827
export const EXECUTOR_WASM_PATH: string = resolvePrepIroha('executor.wasm')
@@ -36,14 +35,14 @@ for (const filePath of [...Object.values(BIN_PATHS), EXECUTOR_WASM_PATH]) {
3635
}
3736
}
3837

39-
export async function irohaCodecToScale(
38+
export async function kagamiCodecToScale(
4039
type: keyof typeof SCHEMA,
4140
json: JsonValue,
4241
): Promise<Uint8Array> {
4342
const input = JSON.stringify(json, undefined, 2)
4443

4544
return new Promise((resolve, reject) => {
46-
const child = spawn(BIN_PATHS.iroha_codec, ['json-to-scale', '--type', type], {
45+
const child = spawn(BIN_PATHS.kagami, ['codec', 'json-to-scale', '--type', type], {
4746
stdio: ['pipe', 'pipe', 'inherit'],
4847
})
4948

@@ -54,7 +53,7 @@ export async function irohaCodecToScale(
5453
})
5554

5655
child.on('close', (code) => {
57-
if (code !== 0) reject(new Error('non-zero exit code of iroha_codec'))
56+
if (code !== 0) reject(new Error('non-zero exit code of kagami'))
5857
resolve(Uint8Array.from(Buffer.concat(chunks)))
5958
})
6059

@@ -63,12 +62,12 @@ export async function irohaCodecToScale(
6362
})
6463
}
6564

66-
export async function irohaCodecToJson(
65+
export async function kagamiCodecToJson(
6766
type: keyof typeof SCHEMA,
6867
scale: Uint8Array,
6968
): Promise<JsonValue> {
7069
return new Promise<JsonValue>((resolve, reject) => {
71-
const child = spawn(BIN_PATHS.iroha_codec, ['scale-to-json', '--type', type], {
70+
const child = spawn(BIN_PATHS.kagami, ['codec', 'scale-to-json', '--type', type], {
7271
stdio: ['pipe', 'pipe', 'inherit'],
7372
})
7473

etc/task-codegen.ts

+1-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import type { Schema } from '@iroha/core/data-model/schema'
21
import SCHEMA from '@iroha/core/data-model/schema-json'
32
import { generateClientFindAPI, generateDataModel, generatePrototypes, Resolver } from './codegen.ts'
4-
import { expect } from '@std/expect'
53
import * as colors from '@std/fmt/colors'
64
import { parseArgs } from 'jsr:@std/cli/parse-args'
75
import { assertEquals } from '@std/assert/equals'
@@ -41,31 +39,7 @@ async function writeAll(entries: { file: string; code: () => string }[]) {
4139
}
4240
}
4341

44-
/**
45-
* There are not included into the schema for some reason, but are useful to generate code for.
46-
*/
47-
const EXTENSION: Schema = {
48-
Status: {
49-
Struct: [
50-
{ name: 'peers', type: 'Compact<u128>' },
51-
{ name: 'blocks', type: 'Compact<u128>' },
52-
{ name: 'txs_accepted', type: 'Compact<u128>' },
53-
{ name: 'txs_rejected', type: 'Compact<u128>' },
54-
{ name: 'uptime', type: 'Uptime' },
55-
{ name: 'view_changes', type: 'Compact<u128>' },
56-
{ name: 'queue_size', type: 'Compact<u128>' },
57-
],
58-
},
59-
Uptime: {
60-
Struct: [
61-
{ name: 'secs', type: 'Compact<u128>' },
62-
{ name: 'nanos', type: 'u32' },
63-
],
64-
},
65-
}
66-
expect(Object.keys(SCHEMA)).not.toContain(Object.keys(EXTENSION))
67-
68-
const resolver = new Resolver({ ...SCHEMA, ...EXTENSION })
42+
const resolver = new Resolver(SCHEMA)
6943

7044
console.time('codegen')
7145
await writeAll([

0 commit comments

Comments
 (0)