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

Feature alliance #1

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions packages/api-derive/src/alliance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0

export * from './proposals';
19 changes: 19 additions & 0 deletions packages/api-derive/src/alliance/proposals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Hash } from '@polkadot/types/interfaces';
import type { DeriveCollectiveProposal } from '../types';

import { Observable } from 'rxjs';

import { proposal as collectiveProposal, proposals as collectiveProposals } from '../collective';
import { memo } from '../util';

export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
return memo(instanceId, collectiveProposal(instanceId, api, 'allianceMotion'));
}

export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposal[]> {
return memo(instanceId, collectiveProposals(instanceId, api, 'allianceMotion'));
}
3 changes: 2 additions & 1 deletion packages/api-derive/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AnyFunction } from '@polkadot/types/types';

import * as accounts from './accounts';
import * as alliance from './alliance';
import * as balances from './balances';
import * as bounties from './bounties';
import * as chain from './chain';
Expand All @@ -32,7 +33,7 @@ interface Avail {
withDetect?: boolean;
}

export const derive = { accounts, balances, bounties, chain, contracts, council, crowdloan, democracy, elections, imOnline, membership, parachains, session, society, staking, technicalCommittee, treasury, tx };
export const derive = { accounts, alliance, balances, bounties, chain, contracts, council, crowdloan, democracy, elections, imOnline, membership, parachains, session, society, staking, technicalCommittee, treasury, tx };

type DeriveSection<Section> = {
[Method in keyof Section]: Section[Method] extends AnyFunction
Expand Down
2 changes: 1 addition & 1 deletion packages/api-derive/src/collective/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0

export type Collective = 'council' | 'membership' | 'technicalCommittee';
export type Collective = 'council' | 'membership' | 'technicalCommittee' | 'allianceMotion';
500 changes: 308 additions & 192 deletions packages/api/src/augment/events.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/api/src/augment/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2017-2021 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable */

import '@polkadot/types/augment';
import './consts';
import './errors';
import './events';
import './query';
import './rpc';
import './tx';
import './rpc';
489 changes: 296 additions & 193 deletions packages/api/src/augment/query.ts

Large diffs are not rendered by default.

528 changes: 316 additions & 212 deletions packages/api/src/augment/tx.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@babel/runtime": "^7.15.4",
"@polkadot/util": "^7.4.1",
"@polkadot/util-crypto": "^7.4.1",
"multihashes": "^4.0.3",
"rxjs": "^7.3.0"
},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions packages/types/src/augment/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable */

import type { BitVec, Bool, Bytes, Data, I128, I16, I256, I32, I64, I8, Json, Null, Raw, StorageKey, Text, Type, U128, U16, U256, U32, U64, U8, USize, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from '@polkadot/types';
import type { BlacklistItem, MemberRole, Url } from '@polkadot/types/interfaces/alliance';
import type { AssetApproval, AssetApprovalKey, AssetBalance, AssetDestroyWitness, AssetDetails, AssetMetadata, TAssetBalance, TAssetDepositBalance } from '@polkadot/types/interfaces/assets';
import type { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/types/interfaces/attestations';
import type { RawAuraPreDigest } from '@polkadot/types/interfaces/aura';
Expand All @@ -13,6 +14,7 @@ import type { BeefyCommitment, BeefyId, BeefyNextAuthoritySet, BeefyPayload, Bee
import type { BridgedBlockHash, BridgedBlockNumber, BridgedHeader, CallOrigin, ChainId, DeliveredMessages, DispatchFeePayment, InboundLaneData, InboundRelayer, InitializationData, LaneId, MessageData, MessageKey, MessageNonce, MessagesDeliveryProofOf, MessagesProofOf, OperatingMode, OutboundLaneData, OutboundMessageFee, OutboundPayload, Parameter, RelayerId, UnrewardedRelayer, UnrewardedRelayersState } from '@polkadot/types/interfaces/bridges';
import type { BlockHash } from '@polkadot/types/interfaces/chain';
import type { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate';
import type { Cid, CidMultihash, CidVersion } from '@polkadot/types/interfaces/cid';
import type { EthereumAddress, StatementKind } from '@polkadot/types/interfaces/claims';
import type { CollectiveOrigin, MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective';
import type { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus';
Expand Down Expand Up @@ -143,6 +145,7 @@ declare module '@polkadot/types/types/registry' {
Bidder: Bidder;
BidKind: BidKind;
BitVec: BitVec;
BlacklistItem: BlacklistItem;
Block: Block;
BlockAttestations: BlockAttestations;
BlockHash: BlockHash;
Expand Down Expand Up @@ -186,6 +189,9 @@ declare module '@polkadot/types/types/registry' {
ChainType: ChainType;
ChangesTrieConfiguration: ChangesTrieConfiguration;
ChangesTrieSignal: ChangesTrieSignal;
Cid: Cid;
CidMultihash: CidMultihash;
CidVersion: CidVersion;
ClassDetails: ClassDetails;
ClassId: ClassId;
ClassMetadata: ClassMetadata;
Expand Down Expand Up @@ -519,6 +525,7 @@ declare module '@polkadot/types/types/registry' {
MaybeRandomness: MaybeRandomness;
MaybeVrf: MaybeVrf;
MemberCount: MemberCount;
MemberRole: MemberRole;
MembershipProof: MembershipProof;
MessageData: MessageData;
MessageId: MessageId;
Expand Down Expand Up @@ -949,6 +956,7 @@ declare module '@polkadot/types/types/registry' {
UpgradeGoAhead: UpgradeGoAhead;
UpgradeRestriction: UpgradeRestriction;
UpwardMessage: UpwardMessage;
Url: Url;
usize: usize;
USize: USize;
ValidationCode: ValidationCode;
Expand Down
53 changes: 53 additions & 0 deletions packages/types/src/generic/CidMultihash.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable new-cap */

import multihashes from 'multihashes';

import { hexToU8a, u8aConcat, u8aEq } from '@polkadot/util';

import { Vec } from '../codec';
import { TypeRegistry } from '../create';
import { u8, u64 } from '../primitive';
import { GenericCidMultihash as CidMultihash } from './CidMultihash';

describe('CidMultihash', (): void => {
const registry = new TypeRegistry();

it('encode CidMultihash from native multihash', (): void => {
const multi = multihashes.fromHexString('12202fe65ccc17fe180c3bf4e9b8490fcc6dc74c30bf6595795dcd1136d8d9cb3f95');

expect(
new CidMultihash(
registry,
u8aConcat(
new u64(registry, multi.slice(0, 1)).toU8a(),
new u8(registry, multi.slice(1, 2)).toU8a(),
multi.slice(2)
)
)
.eq('0x1200000000000000202fe65ccc17fe180c3bf4e9b8490fcc6dc74c30bf6595795dcd1136d8d9cb3f95')
).toBe(true);
});

it('decode CidMultihash', (): void => {
const cidMultihash = new CidMultihash(registry, '0x1200000000000000202fe65ccc17fe180c3bf4e9b8490fcc6dc74c30bf6595795dcd1136d8d9cb3f95');

expect(u8aEq(
cidMultihash.toMultihash(),
hexToU8a('0x12202fe65ccc17fe180c3bf4e9b8490fcc6dc74c30bf6595795dcd1136d8d9cb3f95')
)).toBe(true);
});

it('decode vec<CidMultihash>', (): void => {
const cids = new Vec(registry, 'CidMultihash', '0x081200000000000000202fe65ccc17fe180c3bf4e9b8490fcc6dc74c30bf6595795dcd1136d8d9cb3f951200000000000000202fe65ccc17fe180c3bf4e9b8490fcc6dc74c30bf6595795dcd1136d8d9cb3f95');

expect(
u8aEq(
u8aConcat(...cids.map((cid) => cid.toU8a())),
hexToU8a('0x1200000000000000202fe65ccc17fe180c3bf4e9b8490fcc6dc74c30bf6595795dcd1136d8d9cb3f951200000000000000202fe65ccc17fe180c3bf4e9b8490fcc6dc74c30bf6595795dcd1136d8d9cb3f95')
)
).toBe(true);
});
});
136 changes: 136 additions & 0 deletions packages/types/src/generic/CidMultihash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable new-cap */

import type { HashCode } from 'multihashes';

import multihashes from 'multihashes';

import { isUndefined, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';

import { CodecHash, Hash } from '../interfaces';
import { u8, u64 } from '../primitive';
import { AnyJson, AnyU8a, BareOpts, Codec, Registry } from '../types';

/**
* @name GenericCidMultihash
* @description
* This manages codec arrays. Internally it keeps track of the length (as decoded) and allows
* construction with the passed `Type` in the constructor. It is an extension to Array, providing
* specific encoding/decoding on top of the base type.
*/
export class GenericCidMultihash extends Uint8Array implements Codec {
#code: u64;
#size: u8;
#digest: Uint8Array;

registry: Registry;
createdAtHash?: Hash | undefined;

constructor (registry: Registry, value?: AnyU8a) {
const u8a: Uint8Array = u8aToU8a(value);
const code: u64 = new u64(registry, u8a.slice(0, 8));

const size: u8 = new u8(registry, u8a.slice(8, 9));
const digest: Uint8Array = u8a.slice(9, size.toNumber() + 9);

super(u8aConcat(code.toU8a(), size.toU8a(), digest));

this.#code = code;
this.#size = size;
this.#digest = digest;

this.registry = registry;
}

public get code (): u64 {
return this.#code;
}

public get size (): u8 {
return this.#size;
}

public get digest (): Uint8Array {
return this.#digest;
}

/**
* @description The length of the value when encoded as a Uint8Array
*/
public get encodedLength (): number {
return this.length;
}

/**
* @description returns a hash of the contents
*/
public get hash (): CodecHash {
return this.registry.hash(this.toU8a());
}

/**
* @description Returns true if the type wraps an empty/default all-0 value
*/
public get isEmpty (): boolean {
return !this.encodedLength || isUndefined(this.find((value) => !!value));
}

public eq (other?: unknown): boolean {
if (other instanceof Uint8Array) {
return (this.length === other.length) &&
!this.some((value, index) => value !== other[index]);
}

return this.eq(u8aToU8a(other as any));
}

/**
* @description Returns a hex string representation of the value
*/
public toHex (): string {
return u8aToHex(this.toU8a());
}

/**
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
*/
public toHuman (): AnyJson {
return this.toJSON();
}

/**
* @description Converts the Object to JSON, typically used for RPC transfers
*/
public toJSON (): AnyJson {
return {
code: this.#code.toNumber(),
digest: u8aToHex(this.#digest),
size: this.#size.toNumber()
};
}

/**
* @description Returns the base runtime type name for this instance
*/
public toRawType (): string {
return 'CidMultihash';
}

/**
* @description Encodes the value as a Uint8Array as per the SCALE specifications
* @param isBare true when the value has none of the type-specific prefixes (internal)
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public toU8a (isBare?: BareOpts): Uint8Array {
return this;
}

/**
* @description return ipfs cid's multihash
*/
public toMultihash (): Uint8Array {
return multihashes.encode(this.#digest, this.#code.toNumber() as HashCode, this.#size.toNumber());
}
}
1 change: 1 addition & 0 deletions packages/types/src/generic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { GenericChainProperties } from './ChainProperties';
export { GenericConsensusEngineId } from './ConsensusEngineId';
export { GenericEvent, GenericEventData } from './Event';
export { GenericLookupSource } from './LookupSource';
export { GenericCidMultihash } from './CidMultihash';
export { GenericMultiAddress, GenericMultiAddress as GenericAddress } from './MultiAddress';
export { GenericPortableRegistry } from './PortableRegistry';
export { GenericVote } from './Vote';
27 changes: 27 additions & 0 deletions packages/types/src/interfaces/alliance/definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0

// order important in structs... :)
/* eslint-disable sort-keys */

import type { Definitions } from '../../types';

export default {
rpc: {},
types: {
MemberRole: {
_enum: [
'Founder',
'Fellow',
'Ally'
]
},
Url: 'Vec<u8>',
BlacklistItem: {
_enum: {
AccountId: 'AccountId',
Website: 'Vec<u8>'
}
}
}
} as Definitions;
4 changes: 4 additions & 0 deletions packages/types/src/interfaces/alliance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */

export * from './types';
25 changes: 25 additions & 0 deletions packages/types/src/interfaces/alliance/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */

import type { Bytes, Enum } from '@polkadot/types';
import type { AccountId } from '@polkadot/types/interfaces/runtime';

/** @name BlacklistItem */
export interface BlacklistItem extends Enum {
readonly isAccountId: boolean;
readonly asAccountId: AccountId;
readonly isWebsite: boolean;
readonly asWebsite: Bytes;
}

/** @name MemberRole */
export interface MemberRole extends Enum {
readonly isFounder: boolean;
readonly isFellow: boolean;
readonly isAlly: boolean;
}

/** @name Url */
export interface Url extends Bytes {}

export type PHANTOM_ALLIANCE = 'alliance';
Loading