Skip to content

Commit

Permalink
Adjust support fo US English as per substrate (#811)
Browse files Browse the repository at this point in the history
* Rename ExtinsicStatus Finalised -> Finalized

* Finalised heads -> Finalized
  • Loading branch information
jacogr authored Mar 29, 2019
1 parent 2528ac4 commit 6fef86c
Show file tree
Hide file tree
Showing 26 changed files with 194 additions and 112 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.53.1

- Change spelling to US English as per substrate master (1.0-rc1), potential breaking
- For extrinsic status results, if you have checked the type returns, i.e. `result.type === 'Finalised` now check on the status for `result.status.isFinalized` or `result.status.isBoadcast`, ... (the `type` property is now accessible only on `result.status.type`)
- If using `subscribeFinalisedHeads` update to `subscribeFinalizedHeads` (likewise `'getFinalisedHead` should be updated to `getFinalizedHead` and `derive.bestNumberFinalized`)
- All examples have been updated with sr25519 addesses

# 0.52.1

- Support queries to linked mapped storage (found in new staking interfaces)
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/promise/09_transfer_events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ async function main () {
api.tx.balances
.transfer(recipient, AMOUNT)
.sign(alicePair, { nonce })
.send(({ events = [], status, type }) => {
console.log('Transaction status:', type);
.send(({ events = [], status }) => {
console.log('Transaction status:', status.type);

if (type === 'Finalised') {
console.log('Completed at block hash', status.asFinalised.toHex());
if (status.isFinalized) {
console.log('Completed at block hash', status.asFinalized.toHex());
console.log('Events:');

events.forEach(({ phase, event: { data, method, section } }) => {
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/promise/10_upgrade_chain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ async function main () {
// preform the actual chain upgrade via the sudo module
api.tx.sudo
.sudo(proposal)
.signAndSend(adminPair, ({ events = [], status, type }) => {
console.log('Proposal status:', type);
.signAndSend(adminPair, ({ events = [], status }) => {
console.log('Proposal status:', status.type);

if (type === 'Finalised') {
if (status.isFinalized) {
console.error('You have just upgraded your chain');

console.log('Completed at block hash', status.asFinalised.toHex());
console.log('Completed at block hash', status.asFinalized.toHex());
console.log('Events:');

events.forEach(({ phase, event: { data, method, section } }) => {
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/rx/06_make_transfer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ async function main () {
// Sign and send the transcation
.signAndSend(alice)
// Subscribe to the status updates of the transfer
.subscribe(({ status, type }) => {
if (type === 'Finalised') {
console.log(`Successful transfer of 12345 from Alice to Bob with hash ${status.asFinalised.toHex()}`);
.subscribe(({ status }) => {
if (status.isFinalized) {
console.log(`Successful transfer of 12345 from Alice to Bob with hash ${status.asFinalized.toHex()}`);
} else {
console.log(`Staus of transfer: ${type}`);
console.log(`Staus of transfer: ${status.type}`);
}
});
}
Expand Down
9 changes: 5 additions & 4 deletions docs/examples/rx/09_transfer_events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ async function main () {
// Sign and send it
.signAndSend(alicePair)
// And subscribe to the actual status
.subscribe(({ events = [], status, type }) => {
.subscribe(({ events = [], status }) => {
// Log transfer events
console.log('Transfer status:', type);
console.log('Transfer status:', status.type);

// Log system events once the transfer is finalised
if (type === 'Finalised') {
console.log('Completed at block hash', status.asFinalised.toHex());
if (status.isFinalized) {
console.log('Completed at block hash', status.asFinalized.toHex());
console.log('Events:');

events.forEach(({ phase, event: { data, method, section } }) => {
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/rx/10_upgrade_chain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ async function main () {
// sign and send the proposal
.signAndSend(adminPair)
// subscribe to overall result
.subscribe(({ events = [], status, type }) => {
.subscribe(({ events = [], status }) => {
// Log transfer events
console.log('Proposal status:', type);
console.log('Proposal status:', status.type);

if (type === 'Finalised') {
if (status.isFinalized) {
console.error('You have just upgraded your chain');

console.log('Completed at block hash', status.asFinalised.toHex());
console.log('Completed at block hash', status.asFinalized.toHex());
console.log('Events:');

// Log system events once the chain update is finalised
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import { drr } from '../util/drr';
* <BR>
*
* ```javascript
* api.derive.chain.bestNumberFinalised((blockNumber) => {
* api.derive.chain.bestNumberFinalized((blockNumber) => {
* console.log(`the current finalised block is #${blockNumber}`);
* });
* ```
*/
export function bestNumberFinalised (api: ApiInterface$Rx) {
export function bestNumberFinalized (api: ApiInterface$Rx) {
return (): Observable<BlockNumber> =>
(api.rpc.chain.subscribeFinalisedHeads() as Observable<Header>)
(api.rpc.chain.subscribeFinalizedHeads() as Observable<Header>)
.pipe(
filter((header: Header) => header && !!header.blockNumber),
map(({ blockNumber }: Header) => blockNumber),
Expand Down
8 changes: 4 additions & 4 deletions packages/api-derive/src/chain/bestNumberLag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BlockNumber } from '@polkadot/types';

import { drr } from '../util/drr';
import { bestNumber } from './bestNumber';
import { bestNumberFinalised } from './bestNumberFinalised';
import { bestNumberFinalized } from './bestNumberFinalized';

/**
* @description Calculates the lag between finalised head and best head
Expand All @@ -26,10 +26,10 @@ export function bestNumberLag (api: ApiInterface$Rx) {
return (): Observable<BlockNumber> =>
combineLatest(
bestNumber(api)(),
bestNumberFinalised(api)()
bestNumberFinalized(api)()
).pipe(
map(([bestNumber, bestNumberFinalised]) =>
new BlockNumber(bestNumber.sub(bestNumberFinalised))
map(([bestNumber, bestNumberFinalized]) =>
new BlockNumber(bestNumber.sub(bestNumberFinalized))
),
drr()
);
Expand Down
2 changes: 1 addition & 1 deletion packages/api-derive/src/chain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.

export * from './bestNumber';
export * from './bestNumberFinalised';
export * from './bestNumberFinalized';
export * from './bestNumberLag';
export * from './getHeader';
export * from './subscribeNewHead';
2 changes: 1 addition & 1 deletion packages/api-derive/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('derive', () => {
testFunction(api)('balances', 'votingBalancesNominatorsFor', []);

testFunction(api)('chain', 'bestNumber', []);
testFunction(api)('chain', 'bestNumberFinalised', []);
testFunction(api)('chain', 'bestNumberFinalized', []);

testFunction(api)('democracy', 'referendumInfos', []);
testFunction(api)('democracy', 'referendums', []);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement
* api.tx.balances
* .transfer(<recipientId>, <balance>)
* .signAndSend(<keyPair>, ({status}) => {
* console.log('tx status', status.asFinalised.toHex());
* console.log('tx status', status.asFinalized.toHex());
* });
* ```
*/
Expand Down
16 changes: 4 additions & 12 deletions packages/api/src/SubmittableExtrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.

import { KeyringPair } from '@polkadot/keyring/types';
import { AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Hash, Index, Method, SignedBlock, Struct, Text, Vector } from '@polkadot/types';
import { AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Hash, Index, Method, SignedBlock, Struct, Vector } from '@polkadot/types';
import { Codec, CodecCallback, IExtrinsic, SignatureOptions } from '@polkadot/types/types';
import { ApiInterface$Rx, ApiType, OnCallDefinition, Signer } from './types';

Expand All @@ -29,8 +29,7 @@ export class SubmittableResult extends Struct {
constructor (value?: any) {
super({
events: Vector.with(EventRecord),
status: ExtrinsicStatus,
type: Text
status: ExtrinsicStatus
}, value);
}

Expand All @@ -47,13 +46,6 @@ export class SubmittableResult extends Struct {
get status (): ExtrinsicStatus {
return this.get('status') as ExtrinsicStatus;
}

/**
* @description the type
*/
get type (): string {
return (this.get('type') as Text).toString();
}
}

export interface SubmittableExtrinsic<CodecResult, SubscriptionResult> extends IExtrinsic {
Expand All @@ -79,7 +71,7 @@ export function createSubmittableExtrinsic<CodecResult, SubscriptionResult> (typ
}

function statusObservable (status: ExtrinsicStatus): Observable<SubmittableResult> {
if (status.type !== 'Finalised') {
if (!status.isFinalized) {
return of(
new SubmittableResult({
status,
Expand All @@ -88,7 +80,7 @@ export function createSubmittableExtrinsic<CodecResult, SubscriptionResult> (typ
);
}

const blockHash = status.asFinalised;
const blockHash = status.asFinalized;

return combineLatest(
api.rpc.chain.getBlock(blockHash) as Observable<SignedBlock>,
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/checkTypes.manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export default async function test () {

const unsub = await api.tx.balances
.transfer(keyring.bob.address(), 12345)
.signAndSend(keyring.alice, ({ type }) => {
console.log('transfer status:', type);
.signAndSend(keyring.alice, ({ status }) => {
console.log('transfer status:', status.type);

unsub();
});
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/rx/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ import ApiBase from '../Base';
* )
* )
* // subscribe to overall result
* .subscribe(({ status, type }) => {
* if (type === 'Finalised') {
* console.log('Completed at block hash', status.asFinalised.toHex());
* .subscribe(({ status }) => {
* if (status.isFinalized) {
* console.log('Completed at block hash', status.asFinalized.toHex());
* }
* });
* ```
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/util/filterEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function filterEvents (extHash: U8a, { block: { extrinsics, heade
// find the index of our extrinsic in the block
const index = allHashes.indexOf(myHash);

// if we do get the block after Finalised, it _should_ be there
// if we do get the block after finalized, it _should_ be there
if (index === -1) {
l.warn(`block ${header.hash}: Unable to find extrinsic ${myHash} inside ${allHashes}`);
return;
Expand Down
12 changes: 10 additions & 2 deletions packages/api/test/e2e/promise-queries.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ describe.skip('e2e queries', () => {
});
});

it('subscribes to finalized', (done) => {
api.rpc.chain.subscribeFinalizedHeads((header) => {
expect(header.blockNumber.isZero()).toBe(false);

done();
});
});

it('subscribes to derive', (done) => {
api.derive.chain.subscribeNewHead((header) => {
expect(header.blockNumber.isZero()).toBe(false);
Expand All @@ -62,8 +70,8 @@ describe.skip('e2e queries', () => {
});
});

it('subscribes to queries (default)', (done) => {
api.query.staking.validatorPreferences(keyring.ferdie.address(), (prefs) => {
it.skip('subscribes to queries (default)', (done) => {
api.query.staking.validators(keyring.ferdie.address(), (prefs) => {
expect(prefs.unstakeThreshold.toNumber()).toBe(3);

done();
Expand Down
38 changes: 19 additions & 19 deletions packages/api/test/e2e/promise-tx.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ describe.skip('e2e transactions', () => {
return api.tx.balances
.transfer('12ghjsRJpeJpUQaCQeHcBv9pRQA3tdcMxeL8cVk9JHWJGHjd', 12345)
.sign(keyring.dave, { nonce })
.send(({ events, status, type }) => {
console.log('Transaction status:', type);
.send(({ events, status }) => {
console.log('Transaction status:', status.type);

if (type === 'Finalised') {
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');

Expand All @@ -59,10 +59,10 @@ describe.skip('e2e transactions', () => {
return api.tx.balances
.transfer('12ghjsRJpeJpUQaCQeHcBv9pRQA3tdcMxeL8cVk9JHWJGHjd', 12345)
.sign(keyring.dave, nonce)
.send(({ events, status, type }) => {
console.log('Transaction status:', type);
.send(({ events, status }) => {
console.log('Transaction status:', status.type);

if (type === 'Finalised') {
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');

Expand All @@ -80,10 +80,10 @@ describe.skip('e2e transactions', () => {
it('makes a transfer (signAndSend)', async (done) => {
return api.tx.balances
.transfer('12ghjsRJpeJpUQaCQeHcBv9pRQA3tdcMxeL8cVk9JHWJGHjd', 12345)
.signAndSend(keyring.dave, ({ events, status, type }) => {
console.log('Transaction status:', type);
.signAndSend(keyring.dave, ({ events, status }) => {
console.log('Transaction status:', status.type);

if (type === 'Finalised') {
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');

Expand All @@ -103,10 +103,10 @@ describe.skip('e2e transactions', () => {
api.setSigner(signer);
return api.tx.balances
.transfer('12ghjsRJpeJpUQaCQeHcBv9pRQA3tdcMxeL8cVk9JHWJGHjd', 12345)
.signAndSend(keyring.dave.address(), ({ events, status, type }) => {
console.log('Transaction status:', type);
.signAndSend(keyring.dave.address(), ({ events, status }) => {
console.log('Transaction status:', status.type);

if (type === 'Finalised') {
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');

Expand Down Expand Up @@ -136,7 +136,7 @@ describe.skip('e2e transactions', () => {
//with callback
await expect(api.tx.balances
.transfer('12ghjsRJpeJpUQaCQeHcBv9pRQA3tdcMxeL8cVk9JHWJGHjd', 12345)
.signAndSend(keyring.alice.address(), ({ events, status, type }) => {
.signAndSend(keyring.alice.address(), ({ events, status }) => {
})).rejects.toThrow('does not have the keyringPair');
});

Expand Down Expand Up @@ -164,10 +164,10 @@ describe.skip('e2e transactions', () => {
function doOne (cb) {
return api.tx.balances
.transfer(pair.address(), 123456)
.signAndSend(keyring.dave, ({ events, status, type }) => {
console.log('One: Transaction status:', type);
.signAndSend(keyring.dave, ({ events, status }) => {
console.log('One: Transaction status:', status.type);

if (type === 'Finalised') {
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');

Expand All @@ -183,10 +183,10 @@ describe.skip('e2e transactions', () => {
function doTwo (cb) {
return api.tx.balances
.transfer(keyring.alice.address(), 12345)
.signAndSend(pair, ({ events, status, type }) => {
console.log('One: Transaction status:', type);
.signAndSend(pair, ({ events, status }) => {
console.log('One: Transaction status:', status.type);

if (type === 'Finalised') {
if (status.isFinalized) {
console.log('Completed at block hash', status.value.toHex());
console.log('Events:');

Expand Down
8 changes: 4 additions & 4 deletions packages/api/test/e2e/rx-tx.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe.skip('e2e transactions', () => {
.send()
)
)
.subscribe((status) => {
if (status.type === 'Finalised') {
.subscribe(({ status }) => {
if (status.isFinalized) {
done();
}
});
Expand All @@ -52,8 +52,8 @@ describe.skip('e2e transactions', () => {
.send()
)
)
.subscribe((status) => {
if (status && status.type === 'Finalised') {
.subscribe(({ status }) => {
if (status.isFinalized) {
done();
}
});
Expand Down
Loading

0 comments on commit 6fef86c

Please sign in to comment.