Move additional types to primitive & rpc (#916)

This commit is contained in:
Jaco Greeff
2019-06-12 16:45:45 +12:00
committed by Ian He
parent a0a741d886
commit 7c8ec1f7f5
45 changed files with 83 additions and 92 deletions
+16 -16
View File
@@ -6,7 +6,7 @@ On the Rust side, the codec types and primitive types are implemented via the [p
## Codec types
These are the base types of the codec. They are typically not used directly, but rather inherited from to create specific types. They are the building blocks for declaring custom types:
These are the base types of the codec. They are typically not used directly, but rather inherited from to create specific types. They are the building blocks for declaring custom types:
| **Types** | |
| --- | --- |
@@ -33,12 +33,19 @@ These primitive types are available:
| **Types** | |
| --- | --- |
| [[AccountId]] | A wrapper around an AccountId/PublicKey representation |
| [[AccountIndex]] | A wrapper around an AccountIndex, which is a shortened, variable-length encoding for an Account |
| [[AccountInfo]] | An Account information structure for contracts |
| [[Address]] | A wrapper around an AccountId and/or AccountIndex that is encoded with a prefix |
| [[Bool]] | Representation for a boolean value in the system |
| [[Bytes]] | A Bytes wrapper for `Vec<u8>` |
| [[Data]] | A raw data structure. It is an encoding of a U8a without any length encoding |
| [[Event]] | Wrapper for the actual data that forms part of an [[Event]] |
| [[EventRecord]] | A record for an [[Event]] (as specified by [[Metadata]]) with the specific [[Phase]] of application |
| [[H160]] | Hash containing 160 bits (20 bytes), typically used in blocks, extrinsics and as a sane default |
| [[H256]] | Hash containing 256 bits (32 bytes), typically used in blocks, extrinsics and as a sane default |
| [[H512]] | Hash containing 512 bits (64 bytes), typically used for signatures |
| [[Hash]] | The default hash that is used accross the system. It is just a thin wrapper around [[H256]]
| [[I8]] | An 8-bit signed integer |
| [[I16]] | A 16-bit signed integer |
| [[I32]] | A 32-bit signed integer |
@@ -48,6 +55,7 @@ These primitive types are available:
| [[Method]] | Extrinsic function descriptor, as defined in [the extrinsic format for a node](https://github.com/paritytech/wiki/blob/master/Extrinsic.md#the-extrinsic-format-for-node) |
| [[Moment]] | A wrapper around seconds/timestamps. Internally the representation only has second precicion (aligning with Rust) |
| [[Null]] | Implements a type that does not contain anything (apart from `null`) |
| [[Origin]] | Where Origin occurs, it should be ignored as an internal-only value |
| [[StorageData]] | Data retrieved via Storage queries and data for key-value pairs |
| [[StorageKey]] | A representation of a storage key (typically hashed) in the system |
| [[Text]] | This is a string wrapper, along with the length. |
@@ -63,14 +71,10 @@ These primitive types are available:
## Substrate types
These custom types implement specific types that are found as part of the Substrate core. They're all extensions of one of the codec types:
These custom types implement specific types that are found as part of the Substrate core. They're all extensions of one of the codec types:
| **Types** | |
| --- | --- |
| [[AccountId]] | A wrapper around an AccountId/PublicKey representation |
| [[AccountIndex]] | A wrapper around an AccountIndex, which is a shortened, variable-length encoding for an Account |
| [[AccountInfo]] | An Account information structure for contracts |
| [[Address]] | A wrapper around an AccountId and/or AccountIndex that is encoded with a prefix |
| [[Amount]] | The Substrate Amount representation as a [[Balance]] |
| [[AssetOf]] | The Substrate AssetOf representation as a [[Balance]] |
| [[AttestedCandidate]] | An attested candidate |
@@ -83,23 +87,15 @@ These custom types implement specific types that are found as part of the Substr
| [[BftAuthoritySignature]] | Represents a Bft Hash and Signature pairing, typically used in reporting network behaviour |
| [[BftHashSignature]] | Represents a Bft Hash and Signature pairing, typically used in reporting network behaviour |
| [[BftProposeOutOfTurn]] | A report for out-of-turn proposals |
| [[Block]] | A block encoded with header and extrinsics |
| [[BlockNumber]] | A representation of a Substrate BlockNumber, implemented as a [[U64]] |
| [[CodeHash]] | The default contract code hash that is used accross the system |
| [[Consensus]] | Log item indicating consensus |
| [[Digest]] | A [[Header]] Digest |
| [[DigestItem]] | A [[EnumType]] the specifies the specific item in the logs of a [[Digest]] |
| [[Event]] | Wrapper for the actual data that forms part of an [[Event]] |
| [[EventRecord]] | A record for an [[Event]] (as specified by [[Metadata]]) with the specific [[Phase]] of application |
| [[Exposure]] | A snapshot of the stake backing a single validator in the system |
| [[Extrinsic]] | Representation of an Extrinsic in the system |
| [[ExtrinsicEra]] | The era for an extrinsic, indicating either a mortal or immortal extrinsic |
| [[Extrinsics]] | A [[Vector]] of [[Extrinsic]] |
| [[ExtrinsicSignature]] | A container for the [[Signature]] associated with a specific [[Extrinsic]] |
| [[Gas]] | A gas number type for Substrate, extending [[U64]] |
| [[Hash]] | The default hash that is used accross the system. It is just a thin wrapper around [[H256]] |
| [[Header]] | A [[Block]] header |
| [[HeaderExtended]] | A [[Block]] header with an additional `author` field that indicates the block author] |
| [[IndividualExposure]] | The Substrate IndividualExposure for staking |
| [[InherentOfflineReport]] | Describes the offline-reporting extrinsic |
| [[Justification]] | A generic justification as a stream of [[Bytes]], this is specific per consensus implementation |
@@ -114,7 +110,6 @@ These custom types implement specific types that are found as part of the Substr
| [[NextAuthority]] | The next authority available as [[SessionKey]] |
| [[Nonce]] | The Nonce or number of transactions sent by a specific account |
| [[NonceCompact]] | The Compact<Nonce> or number of transactions sent by a specific account |
| [[Origin]] | Where Origin occurs, it should be ignored as an internal-only value |
| [[ParaId]] | Identifier for a deployed parachain implemented as a [[U32]] |
| [[Perbill]] | Parts per billion (see also [[Permill]]) |
| [[Permill]] | Parts per million (See also [[Perbill]]) |
@@ -145,12 +140,17 @@ These custom types implement specific types that are found as part of the Substr
## RPC types
These types are not used in the runtime, but are rather used in RPC results:
These types are not used in the runtime, but are rather used in RPC results:
| **Types** | |
| --- | --- |
| [[Block]] | A block encoded with header and extrinsics |
| [[ChainProperties]] | Wraps the properties retrieved from the chain via the `system.properties` RPC call |
| [[Digest]] | A [[Header]] Digest |
| [[DigestItem]] | A [[EnumType]] the specifies the specific item in the logs of a [[Digest]] |
| [[ExtrinsicStatus]] | An EnumType that indicates the status of the Extrinsic as been submitted |
| [[Header]] | A [[Block]] header |
| [[HeaderExtended]] | A [[Block]] header with an additional `author` field that indicates the block author] |
| [[Health]] | A system health indicator, reported back over RPC |
| [[Json]] | Wraps the a JSON structure retrieve via RPC. It extends the standard JS Map |
| [[NetworkState]] | Wraps the properties retrieved from the chain via the `system.network_state` RPC call |
+3 -2
View File
@@ -2,14 +2,15 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Codec, CodecTo } from '../types';
import extrinsics from '@plugnet/extrinsics/static';
import AccountId from '../primitive/AccountId';
import Method from '../primitive/Method';
import Text from '../primitive/Text';
import PropIndex from '../type/PropIndex';
import Proposal from '../type/Proposal';
import AccountId from '../type/AccountId';
import { Codec, CodecTo } from '../types';
import createType from './createType';
import Vector from './Vector';
import Tuple from './Tuple';
@@ -7,7 +7,7 @@ import U8a from '../codec/U8a';
import Vector from '../codec/Vector';
import jsonVec from '../json/AccountIdVec.001.json';
import AccountId from './AccountId';
import StorageData from '../primitive/StorageData';
import StorageData from './StorageData';
describe('AccountId', () => {
describe('defaults', () => {
@@ -2,12 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AnyNumber } from '../types';
import BN from 'bn.js';
import { decodeAddress, encodeAddress } from '@plugnet/keyring';
import { bnToBn, isBn, isNumber, isU8a, isHex } from '@plugnet/util';
import U32 from '../primitive/U32';
import { AnyNumber } from '../types';
import U32 from './U32';
export const ENUMSET_SIZE = new BN(64);
@@ -3,8 +3,8 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import Struct from '../codec/Struct';
import Bytes from '../primitive/Bytes';
import U64 from '../primitive/U64';
import Bytes from './Bytes';
import U64 from './U64';
/**
* @name AccountInfo
@@ -10,11 +10,11 @@ import Struct from '../codec/Struct';
import Tuple from '../codec/Tuple';
import U8aFixed from '../codec/U8aFixed';
import { TypeDef, getTypeClass, getTypeDef } from '../codec/createType';
import Null from '../primitive/Null';
import U32 from '../primitive/U32';
import Metadata from '../Metadata';
import { EventMetadata as EventMetadataV0 } from '../Metadata/v0/Events';
import { MetadataEvent as EventMetadataV4 } from '../Metadata/v1/Events';
import Null from './Null';
import U32 from './U32';
const EventTypes: { [index: string]: Constructor<EventData> } = {};
@@ -7,12 +7,12 @@ import Vector from '../codec/Vector';
import json1 from '../json/EventRecord.001.json';
import json2 from '../json/EventRecord.002.json';
import json3 from '../json/EventRecord.003.json';
import AccountId from './AccountId';
import Event from './Event';
import EventRecord from './EventRecord';
import Metadata from '../Metadata';
import metadataV0 from '../Metadata/v0/static';
import metadataV1 from '../Metadata/static';
import AccountId from './AccountId';
import Event from './Event';
import EventRecord from './EventRecord';
describe('EventRecord', () => {
describe('v0', () => {
@@ -7,10 +7,10 @@ import { assert } from '@plugnet/util';
import EnumType from '../codec/EnumType';
import Struct from '../codec/Struct';
import Vector from '../codec/Vector';
import Null from '../primitive/Null';
import U32 from '../primitive/U32';
import Hash from './Hash';
import Event from './Event';
import Null from './Null';
import U32 from './U32';
/**
* @name ApplyExtrinsic
@@ -3,7 +3,8 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { IHash } from '../types';
import H256 from '../primitive/H256';
import H256 from './H256';
/**
* @name Hash
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Null from '../primitive/Null';
import Null from './Null';
/**
* @name Origin
+8
View File
@@ -10,12 +10,19 @@
*/
// NOTE We are exporting Bool as bool to match with Rust (however also using Bool internally),
// so with the renamed versions, epose both cases, allowing createType to work
export { default as AccountId, AccountIdOf } from './AccountId';
export { default as AccountIndex } from './AccountIndex';
export { default as AccountInfo } from './AccountInfo';
export { default as Address } from './Address';
export { default as Event, EventIndex } from './Event';
export { default as EventRecord, EventRecord77 } from './EventRecord';
export { default as Bool, default as bool } from './Bool';
export { default as Bytes } from './Bytes';
export { default as Data } from './Data';
export { default as H160 } from './H160';
export { default as H256 } from './H256';
export { default as H512 } from './H512';
export { default as Hash } from './Hash';
export { default as I8, default as i8 } from './I8';
export { default as I16, default as i16 } from './I16';
export { default as I32, default as i32 } from './I32';
@@ -25,6 +32,7 @@ export { default as I256, default as i256 } from './I256';
export { default as Method } from './Method';
export { default as Moment, MomentOf } from './Moment';
export { default as Null } from './Null';
export { default as Origin } from './Origin';
export { default as StorageData } from './StorageData';
export { default as StorageHasher } from './StorageHasher';
export { default as StorageKey } from './StorageKey';
@@ -7,8 +7,8 @@ import { AnyU8a } from '../types';
import { blake2AsU8a } from '@plugnet/util-crypto';
import Struct from '../codec/Struct';
import Extrinsics from './Extrinsics';
import Hash from './Hash';
import Hash from '../primitive/Hash';
import Extrinsics from '../type/Extrinsics';
import Header, { HeaderValue } from './Header';
export type BlockValue = {
@@ -9,11 +9,11 @@ import Struct from '../codec/Struct';
import Tuple from '../codec/Tuple';
import Vector from '../codec/Vector';
import Bytes from '../primitive/Bytes';
import Hash from '../primitive/Hash';
import U32 from '../primitive/U32';
import U64 from '../primitive/U64';
import AuthorityId from './AuthorityId';
import Hash from './Hash';
import Signature from './Signature';
import AuthorityId from '../type/AuthorityId';
import Signature from '../type/Signature';
/**
* @name AuthoritiesChange
+1 -1
View File
@@ -6,9 +6,9 @@ import { assert } from '@plugnet/util';
import EnumType from '../codec/EnumType';
import Vector from '../codec/Vector';
import Hash from '../primitive/Hash';
import Null from '../primitive/Null';
import Text from '../primitive/Text';
import Hash from '../type/Hash';
/**
* @name Broadcast
@@ -9,11 +9,10 @@ import { blake2AsU8a } from '@plugnet/util-crypto';
import Compact from '../codec/Compact';
import Struct from '../codec/Struct';
import U64 from '../primitive/U64';
import AccountId from './AccountId';
import BlockNumber from './BlockNumber';
import AccountId from '../primitive/AccountId';
import Hash from '../primitive/Hash';
import BlockNumber from '../type/BlockNumber';
import Digest, { DigestItem } from './Digest';
import Hash from './Hash';
export type HeaderValue = {
digest?: Digest | { logs: DigestItem[] },
+1 -1
View File
@@ -5,8 +5,8 @@
import Struct from '../codec/Struct';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import Hash from '../primitive/Hash';
import BlockNumber from '../type/BlockNumber';
import Hash from '../type/Hash';
const JSON_MAP = new Map([
['bestHash', 'best_hash'],
+2 -2
View File
@@ -5,9 +5,9 @@
import { AnyU8a } from '../types';
import Struct from '../codec/Struct';
import Block, { BlockValue } from '../type/Block';
import Hash from '../type/Hash';
import Hash from '../primitive/Hash';
import Justification from '../type/Justification';
import Block, { BlockValue } from './Block';
type SignedBlockValue = {
block?: BlockValue,
+1 -1
View File
@@ -6,7 +6,7 @@ import { AnyU8a } from '../types';
import Struct from '../codec/Struct';
import Vector from '../codec/Vector';
import Hash from '../type/Hash';
import Hash from '../primitive/Hash';
import { KeyValueOption, KeyValueOptionValue } from '../type/KeyValue';
type StorageChangeSetValue = {
+3
View File
@@ -8,8 +8,11 @@
/**
* @summary Type definitions that are used in the rpc
*/
export { default as Block } from './Block';
export { default as ChainProperties } from './ChainProperties';
export { default as Digest, DigestItem } from './Digest';
export { default as ExtrinsicStatus } from './ExtrinsicStatus';
export { default as Header, HeaderExtended } from './Header';
export { default as Health } from './Health';
export { default as Json } from './Json';
export { default as NetworkState } from './NetworkState';
+2 -2
View File
@@ -8,11 +8,11 @@ import EnumType from '../codec/EnumType';
import Struct from '../codec/Struct';
import Tuple from '../codec/Tuple';
import Vector from '../codec/Vector';
import AccountId from '../primitive/AccountId';
import Bytes from '../primitive/Bytes';
import Hash from '../primitive/Hash';
import Null from '../primitive/Null';
import U64 from '../primitive/U64';
import AccountId from './AccountId';
import Hash from './Hash';
import ParaId from './ParaId';
import Signature from './Signature';
import SessionKey from './SessionKey';
+1 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import AccountId from './AccountId';
import AccountId from '../primitive/AccountId';
// Wrapper for a AuthorityId. Same as an normal AccountId, i.e. a wrapper
// around publicKey, however specialized since it specifically points to
+1 -1
View File
@@ -5,8 +5,8 @@
import { AnyU8a } from '../types';
import Tuple from '../codec/Tuple';
import Hash from '../primitive/Hash';
import AuthorityId from './AuthorityId';
import Hash from './Hash';
import Signature from './Signature';
export type BftAuthoritySignatureValue = [AnyU8a, AnyU8a];
+1 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Hash from './Hash';
import Hash from '../primitive/Hash';
/**
* @name CodeHash
+1 -1
View File
@@ -7,11 +7,11 @@ import { assert } from '@plugnet/util';
import Bytes from '../primitive/Bytes';
import EnumType from '../codec/EnumType';
import Struct from '../codec/Struct';
import Hash from '../primitive/Hash';
import U64 from '../primitive/U64';
import Balance from './Balance';
import BlockNumber from './BlockNumber';
import CodeHash from './CodeHash';
import Hash from './Hash';
export class TrieId extends Bytes {
}
-13
View File
@@ -1,13 +0,0 @@
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import U32 from '../primitive/U32';
/**
* @name EventIndex
* @description
* The Substrate EventIndex representation as a [[U32]].
*/
export default class EventIndex extends U32 {
}
+2 -2
View File
@@ -12,9 +12,9 @@ import Compact from '../codec/Compact';
import Struct from '../codec/Struct';
import { FunctionMetadata } from '../Metadata/v0/Modules';
import Method from '../primitive/Method';
import Address from './Address';
import Address from '../primitive/Address';
import Hash from '../primitive/Hash';
import ExtrinsicSignature from './ExtrinsicSignature';
import Hash from './Hash';
type ExtrinsicValue = {
method?: Method
@@ -6,12 +6,12 @@ import { KeyringPair } from '@plugnet/keyring/types';
import { AnyNumber, IExtrinsicSignature, SignatureOptions } from '../types';
import Struct from '../codec/Struct';
import Address from './Address';
import Address from '../primitive/Address';
import Method from '../primitive/Method';
import U8 from '../primitive/U8';
import RuntimeVersion from '../rpc/RuntimeVersion';
import ExtrinsicEra from './ExtrinsicEra';
import Nonce from './NonceCompact';
import RuntimeVersion from '../rpc/RuntimeVersion';
import Signature from './Signature';
import SignaturePayload from './SignaturePayload';
@@ -4,7 +4,7 @@
import Compact from '../codec/Compact';
import Struct from '../codec/Struct';
import AccountId from './AccountId';
import AccountId from '../primitive/AccountId';
import Balance from './Balance';
/**
+1 -1
View File
@@ -7,8 +7,8 @@ import { AnyNumber, AnyU8a } from '../types';
import Struct from '../codec/Struct';
import Vector from '../codec/Vector';
import Bytes from '../primitive/Bytes';
import Hash from '../primitive/Hash';
import U32 from '../primitive/U32';
import Hash from './Hash';
import { BftAuthoritySignature, BftAuthoritySignatureValue } from './Bft';
export type RhdJustificationValue = {
+1 -1
View File
@@ -8,11 +8,11 @@ import { assert } from '@plugnet/util';
import EnumType from '../codec/EnumType';
import Struct from '../codec/Struct';
import Hash from '../primitive/Hash';
import U32 from '../primitive/U32';
import AuthorityId from './AuthorityId';
import { BftHashSignature, BftHashSignatureValue } from './Bft';
import BlockNumber from './BlockNumber';
import Hash from './Hash';
type BftAtReportValueSingle = {
round?: AnyNumber,
+1 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Hash from './Hash';
import Hash from '../primitive/Hash';
/**
* @name SeedOf
+3 -3
View File
@@ -8,11 +8,11 @@ import { AnyNumber, AnyU8a } from '../types';
import { blake2AsU8a } from '@plugnet/util-crypto';
import Struct from '../codec/Struct';
import ExtrinsicEra from './ExtrinsicEra';
import Hash from './Hash';
import Hash from '../primitive/Hash';
import Method from '../primitive/Method';
import Nonce from './NonceCompact';
import RuntimeVersion from '../rpc/RuntimeVersion';
import ExtrinsicEra from './ExtrinsicEra';
import Nonce from './NonceCompact';
type SignaturePayloadValue = {
nonce?: AnyNumber,
+1 -1
View File
@@ -5,7 +5,7 @@
import Compact from '../codec/Compact';
import Struct from '../codec/Struct';
import Vector from '../codec/Vector';
import AccountId from './AccountId';
import AccountId from '../primitive/AccountId';
import Balance from './Balance';
import BlockNumber from './BlockNumber';
import UnlockChunk from './UnlockChunk';
+1 -1
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import Struct from '../codec/Struct';
import AccountId from './AccountId';
import AccountId from '../primitive/AccountId';
import Balance from './Balance';
/**
-11
View File
@@ -8,10 +8,6 @@
/**
* @summary Type definitions that are used in the system
*/
export { default as AccountId, AccountIdOf } from './AccountId';
export { default as AccountIndex } from './AccountIndex';
export { default as AccountInfo } from './AccountInfo';
export { default as Address } from './Address';
export { default as Amount } from './Amount';
export { default as AssetOf } from './AssetOf';
export { default as AttestedCandidate } from './AttestedCandidate';
@@ -20,13 +16,9 @@ export { default as Balance, BalanceOf } from './Balance';
export { default as BalanceLock } from './BalanceLock';
// NOTE Bft items are only used in internal structures
// export * from './Bft;
export { default as Block } from './Block';
export { default as BlockNumber } from './BlockNumber';
export { default as CodeHash } from './CodeHash';
export { default as ContractInfo } from './ContractInfo';
export { default as Digest, DigestItem } from './Digest';
export { default as Event, EventIndex } from './Event';
export { default as EventRecord, EventRecord77 } from './EventRecord';
export { default as Exposure } from './Exposure';
export { default as Extrinsic } from './Extrinsic';
export { default as ExtrinsicEra } from './ExtrinsicEra';
@@ -34,8 +26,6 @@ export { default as ExtrinsicSignature } from './ExtrinsicSignature';
// NOTE Only used internally, exported as PendingExtrinsics
// export { default as Extrinsics } from './Extrinsics';
export { default as Gas } from './Gas';
export { default as Hash } from './Hash';
export { default as Header, HeaderExtended } from './Header';
export { default as IndividualExposure } from './IndividualExposure';
export { default as InherentOfflineReport } from './InherentOfflineReport';
export { default as Key } from './Key';
@@ -48,7 +38,6 @@ export { default as NewAccountOutcome } from './NewAccountOutcome';
export { default as Index } from './Nonce';
export { default as IndexCompact } from './NonceCompact';
export { default as Justification } from './Justification';
export { default as Origin } from './Origin';
export { default as ParaId } from './ParaId';
export { default as Permill } from './Permill';
export { default as Perbill } from './Perbill';
+3 -1
View File
@@ -3,10 +3,12 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringPair } from '@plugnet/keyring/types';
import BN from 'bn.js';
import U8a from './codec/U8a';
import Method from './primitive/Method';
import Address from './type/Address';
import Address from './primitive/Address';
import { FunctionMetadata } from './Metadata/v0/Modules';
export type CodecArg = Codec | BN | Boolean | String | Uint8Array | boolean | number | string | undefined | CodecArgArray | CodecArgObject;