Commit 6203cdc4 authored by Amaury Martiny's avatar Amaury Martiny
Browse files

Configurable era

parent 0744bf01
...@@ -57,12 +57,16 @@ export interface TxInfo { ...@@ -57,12 +57,16 @@ export interface TxInfo {
* The recipient address, ss-58 encoded * The recipient address, ss-58 encoded
*/ */
to: string; to: string;
/**
* The amount of time (in minutes) the transaction is valid for. Will be translated
* into a mortal era
*/
validityPeriod: number;
} }
// Calculting Era. The default here allows for 240min mortal eras. // Useful constants for calculting an Era.
const BLOCKTIME = 6; const BLOCKTIME = 6;
const ONE_MINUTE = 60 / BLOCKTIME; const ONE_SECOND = 1 / BLOCKTIME;
const DEFAULT_MORTAL_LENGTH = 240 * ONE_MINUTE;
/** /**
* Construct a balance transfer transaction offline. Transactions can be * Construct a balance transfer transaction offline. Transactions can be
...@@ -83,7 +87,7 @@ export function balanceTransfer(info: TxInfo): UnsignedTransaction { ...@@ -83,7 +87,7 @@ export function balanceTransfer(info: TxInfo): UnsignedTransaction {
blockNumber: createType(registry, 'BlockNumber', info.blockNumber).toHex(), blockNumber: createType(registry, 'BlockNumber', info.blockNumber).toHex(),
era: createType(registry, 'ExtrinsicEra', { era: createType(registry, 'ExtrinsicEra', {
current: info.blockNumber, current: info.blockNumber,
period: DEFAULT_MORTAL_LENGTH period: ONE_SECOND * info.validityPeriod
}).toHex(), }).toHex(),
genesisHash: info.genesisHash, genesisHash: info.genesisHash,
metadataRpc: info.metadataRpc, metadataRpc: info.metadataRpc,
......
...@@ -21,7 +21,8 @@ export const TEST_TX_INFO: TxInfo = { ...@@ -21,7 +21,8 @@ export const TEST_TX_INFO: TxInfo = {
nonce: 2, nonce: 2,
specVersion: 1019, specVersion: 1019,
tip: 0, tip: 0,
to: 'Fy2rsYCoowQBtuFXqLE65ehAY9T6KWcGiNCQAyPDCkfpm4s' to: 'Fy2rsYCoowQBtuFXqLE65ehAY9T6KWcGiNCQAyPDCkfpm4s',
validityPeriod: 240 * 60
}; };
/** /**
......
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