Use Edgeware types from npm (#2351)

This commit is contained in:
Jaco Greeff 2020-03-09 07:30:42 +01:00 committed by GitHub
parent 0ff21d4f28
commit ceaa244fa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1 additions and 298 deletions

View File

@ -1,90 +0,0 @@
/* eslint-disable comma-dangle */
/* eslint-disable lines-between-class-members */
/* eslint-disable @typescript-eslint/camelcase */
import { Bytes, Text, u32, Null } from '@polkadot/types';
import { Option, Struct, Enum } from '@polkadot/types/codec';
import { AccountId } from '@polkadot/types/interfaces';
import { Registry } from '@polkadot/types/types';
export class MetadataRecord extends Struct {
constructor (registry: Registry, value: any) {
super(registry, {
avatar: Text,
display_name: Text,
tagline: Text,
}, value);
}
get avatar (): Text {
return this.get('avatar') as Text;
}
get display_name (): Text {
return this.get('display_name') as Text;
}
get tagline (): Text {
return this.get('tagline') as Text;
}
}
export class Registered extends Null { }
export class Attested extends Null { }
export class Verified extends Null { }
export class IdentityStage extends Enum {
constructor (registry: Registry, value?: string, index?: number) {
super(registry, {
registered: Registered,
attested: Attested,
verified: Verified,
}, value, index);
}
}
export class IdentityRecord extends Struct {
constructor (registry: Registry, value: any) {
super(registry, {
account: 'AccountId',
identity_type: Text,
identity: Bytes,
stage: IdentityStage,
expiration_time: u32,
proof: Option.with(Text),
metadata: Option.with(MetadataRecord),
}, value);
}
get account (): AccountId {
return this.get('account') as AccountId;
}
get identity (): Bytes {
return this.get('identity') as Bytes;
}
get stage (): IdentityStage {
return this.get('stage') as IdentityStage;
}
get expiration_time (): u32 {
return this.get('expiration_time') as u32;
}
get proof (): Option<Text> {
return this.get('proof') as Option<Text>;
}
get metadata (): Option<MetadataRecord> {
return this.get('metadata') as Option<MetadataRecord>;
}
}
// Old types that aren't used anymore (kept for backwards compatability)
const ArchivedTypes = {
IdentityIndex: u32,
Claim: Bytes,
};
// Current types
const CurrentTypes = {
IdentityStage,
IdentityRecord,
MetadataRecord,
IdentityType: Text,
Attestation: Bytes,
Identity: Bytes,
};
export const IdentityTypes = { ...ArchivedTypes, ...CurrentTypes };

View File

@ -1,11 +0,0 @@
import { IdentityTypes } from './identity';
import { SignalingTypes } from './signaling';
import { TreasuryRewardTypes } from './treasuryReward';
import { VotingTypes } from './voting';
export const EdgewareTypes = {
...IdentityTypes,
...SignalingTypes,
...TreasuryRewardTypes,
...VotingTypes
};

View File

@ -1,54 +0,0 @@
/* eslint-disable comma-dangle */
/* eslint-disable lines-between-class-members */
/* eslint-disable @typescript-eslint/camelcase */
import { u32, Text, u64, Bytes } from '@polkadot/types';
import { Struct } from '@polkadot/types/codec';
import { AccountId } from '@polkadot/types/interfaces';
import { Registry } from '@polkadot/types/types';
import { VotingTypes, VoteStage } from './voting';
export class ProposalRecord extends Struct {
constructor (registry: Registry, value: any) {
super(registry, {
index: u32,
author: 'AccountId',
stage: VoteStage,
transition_time: u32,
title: Text,
contents: Text,
vote_id: u64,
}, value);
}
get index (): u32 {
return this.get('index') as u32;
}
get author (): AccountId {
return this.get('author') as AccountId;
}
get stage (): VoteStage {
return this.get('stage') as VoteStage;
}
get transition_time (): u32 {
return this.get('transition_time') as u32;
}
get title (): Text {
return this.get('title') as Text;
}
get contents (): Text {
return this.get('contents') as Text;
}
get vote_id (): u64 {
return this.get('vote_id') as u64;
}
}
export const SignalingTypes = {
PreVoting: VotingTypes.PreVoting,
Voting: VotingTypes.Voting,
Completed: VotingTypes.Completed,
Commit: VotingTypes.Commit,
VoteStage,
ProposalRecord,
ProposalContents: Bytes,
ProposalTitle: Bytes,
};

View File

@ -1,7 +0,0 @@
import { u128 } from '@polkadot/types';
export class Balance2 extends u128 { }
export const TreasuryRewardTypes = {
Balance2
};

View File

@ -1,134 +0,0 @@
/* eslint-disable comma-dangle */
/* eslint-disable lines-between-class-members */
/* eslint-disable @typescript-eslint/camelcase */
import { Null, bool, u64, Enum, Struct, Vec, Tuple, Option, u128 } from '@polkadot/types';
import U8aFixed from '@polkadot/types/codec/U8aFixed';
import { AccountId } from '@polkadot/types/interfaces';
import { AnyU8a, Registry } from '@polkadot/types/types';
export class PreVoting extends Null { }
export class Commit extends Null { }
export class Voting extends Null { }
export class Completed extends Null { }
export class VoteStage extends Enum {
constructor (registry: Registry, value?: string, index?: number) {
super(registry, {
prevoting: PreVoting,
commit: Commit,
voting: Voting,
completed: Completed,
}, value, index);
}
}
export class Binary extends Null { }
export class MultiOption extends Null { }
export class RankedChoice extends Null { }
export class VoteType extends Enum {
constructor (registry: Registry, value?: string, index?: number) {
super(registry, {
binary: Binary,
multioption: MultiOption,
rankedchoice: RankedChoice,
}, value, index);
}
}
export class OnePerson extends Null { }
export class OneCoin extends Null { }
export class TallyType extends Enum {
constructor (registry: Registry, value?: string, index?: number) {
super(registry, {
oneperson: OnePerson,
onecoin: OneCoin,
}, value, index);
}
}
export class VoteOutcome extends U8aFixed {
constructor (registry: Registry, value?: AnyU8a) {
super(registry, value, 256);
}
}
export class Tally extends Option.with(Vec.with(Tuple.with([VoteOutcome, u128]))) { }
export class VoteData extends Struct {
constructor (registry: Registry, value: any) {
super(registry, {
initiator: 'AccountId',
stage: VoteStage,
vote_type: VoteType,
tally_type: TallyType,
is_commit_reveal: bool,
}, value);
}
get initiator (): AccountId {
return this.get('initiator') as AccountId;
}
get stage (): VoteStage {
return this.get('stage') as VoteStage;
}
get vote_type (): VoteType {
return this.get('vote_type') as VoteType;
}
get tally_type (): TallyType {
return this.get('tally_type') as TallyType;
}
get is_commit_reveal (): bool {
return this.get('is_commit_reveal') as bool;
}
}
export class Commitments extends Vec.with(Tuple.with(['AccountId', VoteOutcome])) { }
export class Reveals extends Vec.with(Tuple.with(['AccountId', Vec.with(VoteOutcome)])) { }
export class VoteRecord extends Struct {
constructor (registry: Registry, value: any) {
super(registry, {
id: u64,
commitments: Commitments,
reveals: Reveals,
data: VoteData,
outcomes: Vec.with(VoteOutcome),
}, value);
}
get id (): u64 {
return this.get('id') as u64;
}
get commitments (): Commitments {
return this.get('commits') as Commitments;
}
get reveals (): Reveals {
return this.get('reveals') as Reveals;
}
get data (): VoteData {
return this.get('data') as VoteData;
}
get outcomes (): Vec<VoteOutcome> {
return this.get('outcomes') as Vec<VoteOutcome>;
}
}
export const VotingTypes = {
PreVoting,
Commit,
Voting,
Completed,
VoteStage,
Binary,
MultiOption,
VoteType,
OnePerson,
OneCoin,
TallyType,
VoteOutcome,
Tally,
VoteData,
VoteRecord,
'voting::VoteType': VoteType,
'voting::TallyType': TallyType,
};

View File

@ -2,8 +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 { EdgewareTypes } from 'edgeware-node-types/dist';
import { EdgewareTypes } from './edgeware-node-types';
import { EdgewareTypes } from 'edgeware-node-types/dist';
export default {
...EdgewareTypes,