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

Configurable era

parent 0744bf01
......@@ -57,12 +57,16 @@ export interface TxInfo {
* The recipient address, ss-58 encoded
*/
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 ONE_MINUTE = 60 / BLOCKTIME;
const DEFAULT_MORTAL_LENGTH = 240 * ONE_MINUTE;
const ONE_SECOND = 1 / BLOCKTIME;
/**
* Construct a balance transfer transaction offline. Transactions can be
......@@ -83,7 +87,7 @@ export function balanceTransfer(info: TxInfo): UnsignedTransaction {
blockNumber: createType(registry, 'BlockNumber', info.blockNumber).toHex(),
era: createType(registry, 'ExtrinsicEra', {
current: info.blockNumber,
period: DEFAULT_MORTAL_LENGTH
period: ONE_SECOND * info.validityPeriod
}).toHex(),
genesisHash: info.genesisHash,
metadataRpc: info.metadataRpc,
......
......@@ -21,7 +21,8 @@ export const TEST_TX_INFO: TxInfo = {
nonce: 2,
specVersion: 1019,
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