Commit 0744bf01 authored by Amaury Martiny's avatar Amaury Martiny
Browse files

Refactor: No metadataRpc in createSignedTx

parent b5b9c201
...@@ -7,7 +7,13 @@ import { EXTRINSIC_VERSION } from './util/constants'; ...@@ -7,7 +7,13 @@ import { EXTRINSIC_VERSION } from './util/constants';
/** /**
* JSON format for an unsigned transaction * JSON format for an unsigned transaction
*/ */
export interface UnsignedTransaction extends SignerPayloadJSON {} // eslint-disable-line @typescript-eslint/no-empty-interface export interface UnsignedTransaction extends SignerPayloadJSON {
/**
* The SCALE-encoded metadata, as a hex string. Can be retrieved via the RPC
* call `state_getMetadata`
*/
metadataRpc: string;
}
export interface TxInfo { export interface TxInfo {
/** /**
...@@ -80,6 +86,7 @@ export function balanceTransfer(info: TxInfo): UnsignedTransaction { ...@@ -80,6 +86,7 @@ export function balanceTransfer(info: TxInfo): UnsignedTransaction {
period: DEFAULT_MORTAL_LENGTH period: DEFAULT_MORTAL_LENGTH
}).toHex(), }).toHex(),
genesisHash: info.genesisHash, genesisHash: info.genesisHash,
metadataRpc: info.metadataRpc,
method, method,
nonce: createType(registry, 'Compact<Index>', info.nonce).toHex(), nonce: createType(registry, 'Compact<Index>', info.nonce).toHex(),
specVersion: createType(registry, 'u32', info.specVersion).toHex(), specVersion: createType(registry, 'u32', info.specVersion).toHex(),
......
import { balanceTransfer } from './balanceTransfer'; import { balanceTransfer } from './balanceTransfer';
import { createSignedTx } from './createSignedTx'; import { createSignedTx } from './createSignedTx';
import { createSigningPayload } from './createSigningPayload'; import { createSigningPayload } from './createSigningPayload';
import { metadataRpc, signWithAlice, TEST_TX_INFO } from './util/testUtil'; import { signWithAlice, TEST_TX_INFO } from './util/testUtil';
describe('createSignedTx', () => { describe('createSignedTx', () => {
it('should work', async done => { it('should work', async done => {
...@@ -9,7 +9,7 @@ describe('createSignedTx', () => { ...@@ -9,7 +9,7 @@ describe('createSignedTx', () => {
const signingPayload = createSigningPayload(unsigned); const signingPayload = createSigningPayload(unsigned);
const signature = await signWithAlice(signingPayload); const signature = await signWithAlice(signingPayload);
const tx = createSignedTx(unsigned, signature, metadataRpc); const tx = createSignedTx(unsigned, signature);
expect(tx).toBe( expect(tx).toBe(
'0x2d0284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d003d0fdf8b55e6712b2766d80e9a4f527c3deb3d728a815db77df52d766643cdab3170e25ccd867a4d16c0a8f648b753cd95fed0b46ace6cc4e6e5942712409908eb5808000600ff96074594cccf1cd185fa8a72ceaeefd86648f8d45514f3ce33c31bdd07e4655d30' '0x2d0284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d003d0fdf8b55e6712b2766d80e9a4f527c3deb3d728a815db77df52d766643cdab3170e25ccd867a4d16c0a8f648b753cd95fed0b46ace6cc4e6e5942712409908eb5808000600ff96074594cccf1cd185fa8a72ceaeefd86648f8d45514f3ce33c31bdd07e4655d30'
); );
......
...@@ -14,11 +14,10 @@ import { UnsignedTransaction } from './balanceTransfer'; ...@@ -14,11 +14,10 @@ import { UnsignedTransaction } from './balanceTransfer';
*/ */
export function createSignedTx( export function createSignedTx(
unsigned: UnsignedTransaction, unsigned: UnsignedTransaction,
signature: string, signature: string
metadataRpc: string
): string { ): string {
const registry = new TypeRegistry(); const registry = new TypeRegistry();
registry.setMetadata(new Metadata(registry, metadataRpc)); registry.setMetadata(new Metadata(registry, unsigned.metadataRpc));
const extrinsic = createType( const extrinsic = createType(
registry, registry,
......
...@@ -2,7 +2,7 @@ import { balanceTransfer } from './balanceTransfer'; ...@@ -2,7 +2,7 @@ import { balanceTransfer } from './balanceTransfer';
import { createSignedTx } from './createSignedTx'; import { createSignedTx } from './createSignedTx';
import { createSigningPayload } from './createSigningPayload'; import { createSigningPayload } from './createSigningPayload';
import { decodeTx } from './decodeTx'; import { decodeTx } from './decodeTx';
import { metadataRpc, signWithAlice, TEST_TX_INFO } from './util/testUtil'; import { signWithAlice, TEST_TX_INFO } from './util/testUtil';
describe('decodeTx', () => { describe('decodeTx', () => {
it('should work', async done => { it('should work', async done => {
...@@ -10,9 +10,9 @@ describe('decodeTx', () => { ...@@ -10,9 +10,9 @@ describe('decodeTx', () => {
const signingPayload = createSigningPayload(unsigned); const signingPayload = createSigningPayload(unsigned);
const signature = await signWithAlice(signingPayload); const signature = await signWithAlice(signingPayload);
const tx = createSignedTx(unsigned, signature, metadataRpc); const tx = createSignedTx(unsigned, signature);
const txInfo = decodeTx(tx, metadataRpc); const txInfo = decodeTx(tx, unsigned.metadataRpc);
(['address', 'amount', 'nonce', 'tip', 'to'] as const).forEach(key => (['address', 'amount', 'nonce', 'tip', 'to'] as const).forEach(key =>
expect(txInfo[key]).toBe(TEST_TX_INFO[key]) expect(txInfo[key]).toBe(TEST_TX_INFO[key])
......
...@@ -6,8 +6,6 @@ import { cryptoWaitReady } from '@polkadot/util-crypto'; ...@@ -6,8 +6,6 @@ import { cryptoWaitReady } from '@polkadot/util-crypto';
import { TxInfo } from '../balanceTransfer'; import { TxInfo } from '../balanceTransfer';
export { metadataRpc };
/** /**
* @ignore * @ignore
*/ */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment