diff --git a/packages/api/test/e2e/promise-tx.spec.js b/packages/api/test/e2e/promise-tx.spec.js index 43e233b7ab..8f2c09331a 100644 --- a/packages/api/test/e2e/promise-tx.spec.js +++ b/packages/api/test/e2e/promise-tx.spec.js @@ -24,12 +24,23 @@ describe.skip('e2e transactions', () => { it('makes a transfer', async (done) => { const nonce = await api.query.system.accountNonce(keyring.dave.address()); - await api.tx.balances + api.tx.balances .transfer('12ghjsRJpeJpUQaCQeHcBv9pRQA3tdcMxeL8cVk9JHWJGHjd', 12345) .sign(keyring.dave, nonce) - .send((status) => { - if (status.type === 'Finalised' && status.events && status.events.length) { - done(); + .send(({ events, status, type }) => { + console.log('Transaction status:', type); + + if (type === 'Finalised') { + console.log('Completed at block hash', status.value.toHex()); + console.log('Events:'); + + events.forEach(({ phase, event: { data, method, section } }) => { + console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString()); + }); + + if (events.length) { + done(); + } } }); }); diff --git a/packages/type-extrinsics/src/index.spec.ts b/packages/type-extrinsics/src/index.spec.ts index ab0c3e2331..42d4e05dd9 100644 --- a/packages/type-extrinsics/src/index.spec.ts +++ b/packages/type-extrinsics/src/index.spec.ts @@ -20,7 +20,7 @@ describe('extrinsics', () => { new Uint8Array() ).toU8a(true) ).toEqual(new Uint8Array([ - 129, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 213, 157 + 129, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 73, 19, 0, 0, 0, 213, 157 ])); }); @@ -30,7 +30,7 @@ describe('extrinsics', () => { extrinsics.balances.transfer(keyring.bob.publicKey(), 6969) ).sign(keyring.alice, 0, '0xec7afaf1cca720ce88c1d1b689d81f0583cc15a97d621cf046dd9abf605ef22f').toU8a() ).toEqual(new Uint8Array([ - 65, 2, 129, 255, 209, 114, 167, 76, 218, 76, 134, 89, 18, 195, 43, 160, 168, 10, 87, 174, 105, 171, 174, 65, 14, 92, 203, 89, 222, 232, 78, 47, 68, 50, 219, 79, 78, 239, 232, 24, 167, 219, 153, 211, 226, 132, 22, 151, 169, 47, 140, 198, 86, 169, 91, 159, 253, 98, 242, 111, 12, 143, 192, 226, 250, 233, 158, 232, 195, 57, 44, 184, 25, 65, 228, 143, 200, 140, 84, 111, 179, 102, 187, 61, 1, 137, 148, 74, 168, 246, 131, 243, 228, 64, 10, 106, 138, 117, 209, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 255, 215, 86, 142, 95, 10, 126, 218, 103, 168, 38, 145, 255, 55, 154, 196, 187, 164, 249, 201, 184, 89, 254, 119, 155, 93, 70, 54, 59, 97, 173, 45, 185, 229, 108 + 37, 2, 129, 255, 209, 114, 167, 76, 218, 76, 134, 89, 18, 195, 43, 160, 168, 10, 87, 174, 105, 171, 174, 65, 14, 92, 203, 89, 222, 232, 78, 47, 68, 50, 219, 79, 148, 105, 162, 165, 130, 138, 239, 1, 131, 69, 7, 221, 50, 12, 137, 86, 22, 117, 195, 168, 94, 166, 49, 143, 78, 169, 34, 247, 161, 99, 134, 204, 95, 205, 47, 14, 216, 95, 190, 220, 24, 13, 75, 218, 172, 137, 229, 86, 11, 246, 111, 80, 204, 192, 213, 13, 101, 245, 230, 65, 33, 21, 129, 6, 0, 0, 2, 0, 255, 215, 86, 142, 95, 10, 126, 218, 103, 168, 38, 145, 255, 55, 154, 196, 187, 164, 249, 201, 184, 89, 254, 119, 155, 93, 70, 54, 59, 97, 173, 45, 185, 229, 108 ])); }); }); diff --git a/packages/types/src/Extrinsic.spec.ts b/packages/types/src/Extrinsic.spec.ts index eb60a648f5..ada99676e9 100644 --- a/packages/types/src/Extrinsic.spec.ts +++ b/packages/types/src/Extrinsic.spec.ts @@ -21,7 +21,7 @@ describe('Extrinsic', () => { }); it('decodes an actual transaction with indexes', () => { - const extrinsic = new Extrinsic('0x8110f8e1ebdd3cdef7423d24fe68f3863945ea21c190907d7f3394ddf153f633c77b894af36f7a36e7ec767f4593bfd8d084b66d805605905054327a08ff604187080100000000000000270e0200ff0e6422725af0e9aede3bef6eba77bc87afadf60b9735057ae93801f4c472ad7b00407a10f35a00000000000000000000'); + const extrinsic = new Extrinsic('0x8110f8e1ebdd3cdef7423d24fe68f3863945ea21c190907d7f3394ddf153f633c77b894af36f7a36e7ec767f4593bfd8d084b66d805605905054327a08ff6041870804270e0200ff0e6422725af0e9aede3bef6eba77bc87afadf60b9735057ae93801f4c472ad7b00407a10f35a00000000000000000000'); expect(extrinsic.isSigned).toEqual(true); expect(extrinsic.signature.signer.toU8a()).toEqual(new Uint8Array([0x10])); diff --git a/packages/types/src/ExtrinsicSignature.ts b/packages/types/src/ExtrinsicSignature.ts index fdf63411ad..ca5e3bd055 100644 --- a/packages/types/src/ExtrinsicSignature.ts +++ b/packages/types/src/ExtrinsicSignature.ts @@ -11,7 +11,7 @@ import Struct from './codec/Struct'; import Address from './Address'; import ExtrinsicEra from './ExtrinsicEra'; import Method from './Method'; -import Nonce from './Nonce'; +import Nonce from './NonceCompact'; import Signature from './Signature'; import SignaturePayload from './SignaturePayload'; diff --git a/packages/types/src/NonceCompact.ts b/packages/types/src/NonceCompact.ts new file mode 100644 index 0000000000..c5c950dd97 --- /dev/null +++ b/packages/types/src/NonceCompact.ts @@ -0,0 +1,15 @@ +// Copyright 2017-2018 @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 Compact from './codec/Compact'; +import Nonce from './Nonce'; + +/** + * @name Nonce + * @description + * The Compact or number of transactions sent by a specific account. Generally used + * with extrinsics to determine the order of execution. + */ +export default class NonceCompact extends Compact.with(Nonce) { +} diff --git a/packages/types/src/SignaturePayload.ts b/packages/types/src/SignaturePayload.ts index 3932a05467..5d83b651ef 100644 --- a/packages/types/src/SignaturePayload.ts +++ b/packages/types/src/SignaturePayload.ts @@ -8,7 +8,7 @@ import { AnyNumber, AnyU8a } from './types'; import Struct from './codec/Struct'; import Method from './Method'; import Hash from './Hash'; -import Nonce from './Nonce'; +import Nonce from './NonceCompact'; import ExtrinsicEra from './ExtrinsicEra'; type SignaturePayloadValue = { diff --git a/packages/types/src/Type.ts b/packages/types/src/Type.ts index 199c835297..bf17991c90 100644 --- a/packages/types/src/Type.ts +++ b/packages/types/src/Type.ts @@ -52,6 +52,8 @@ export default class Type extends Text { // alias () -> Null Type._alias('\\\(\\\)', 'Null'), // alias Vec -> Bytes + Type._alias('Compact', 'IndexCompact'), + // alias Vec -> Bytes Type._alias('Vec', 'Bytes'), // alias RawAddress -> Address Type._alias('RawAddress', 'Address'), diff --git a/packages/types/src/codec/Compact.ts b/packages/types/src/codec/Compact.ts index f39e1cfd07..960307e8f7 100644 --- a/packages/types/src/codec/Compact.ts +++ b/packages/types/src/codec/Compact.ts @@ -21,7 +21,7 @@ import Moment from '../Moment'; * a number and making the compact representation thereof */ export default class Compact extends Base implements Codec { - constructor (Type: Constructor, value: AnyNumber = 0) { + constructor (Type: Constructor, value: Compact | AnyNumber = 0) { super(Compact.decodeCompact(Type, value)); } @@ -48,8 +48,10 @@ export default class Compact extends Base implements Codec { return value; } - static decodeCompact (Type: Constructor, value: AnyNumber): Moment | UInt { - if (isString(value)) { + static decodeCompact (Type: Constructor, value: Compact | AnyNumber): Moment | UInt { + if (value instanceof Compact) { + return new Type(value.raw); + } else if (isString(value)) { return new Type( isHex(value) ? hexToBn(value) diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 8b58ab6390..34b29cfb7b 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -60,6 +60,7 @@ export { default as NewAccountOutcome } from './NewAccountOutcome'; export { default as Null } from './Null'; // NOTE Nonce is renamed to Index 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';