Unverified Commit d480fb9d authored by Amaury Martiny's avatar Amaury Martiny Committed by GitHub
Browse files

feat: Add balances::transfer_keep_alive (#4)

* feat: Add balances::transfer_keep_alive

* Fix logic
parent 9e2988f2
...@@ -2,6 +2,18 @@ ...@@ -2,6 +2,18 @@
# @amaurymartiny/txwrapper # @amaurymartiny/txwrapper
# txwrapper # @amaurymartiny/txwrapper
```bash
yarn add @amaurymartiny/txwrapper
```
In a JS file:
```typescript
import { generateKeypair } from '@amaurymartiny/txwrapper';
console.log(generateKeypair().address);
```
Go to [documentation](https://github.com/amaurymartiny/txwrapper/tree/master/docs/globals.md). Go to [documentation](https://github.com/amaurymartiny/txwrapper/tree/master/docs/globals.md) for all the functions.
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
* [blockHash](_balancetransfer_.txinfo.md#blockhash) * [blockHash](_balancetransfer_.txinfo.md#blockhash)
* [blockNumber](_balancetransfer_.txinfo.md#blocknumber) * [blockNumber](_balancetransfer_.txinfo.md#blocknumber)
* [genesisHash](_balancetransfer_.txinfo.md#genesishash) * [genesisHash](_balancetransfer_.txinfo.md#genesishash)
* [keepAlive](_balancetransfer_.txinfo.md#optional-keepalive)
* [metadataRpc](_balancetransfer_.txinfo.md#metadatarpc) * [metadataRpc](_balancetransfer_.txinfo.md#metadatarpc)
* [nonce](_balancetransfer_.txinfo.md#nonce) * [nonce](_balancetransfer_.txinfo.md#nonce)
* [specVersion](_balancetransfer_.txinfo.md#specversion) * [specVersion](_balancetransfer_.txinfo.md#specversion)
...@@ -28,7 +29,7 @@ ...@@ -28,7 +29,7 @@
**address**: *string* **address**: *string*
*Defined in [src/balanceTransfer.ts:22](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L22)* *Defined in [src/balanceTransfer.ts:22](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L22)*
The ss-58 encoded address The ss-58 encoded address
...@@ -38,7 +39,7 @@ ___ ...@@ -38,7 +39,7 @@ ___
**amount**: *number* **amount**: *number*
*Defined in [src/balanceTransfer.ts:26](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L26)* *Defined in [src/balanceTransfer.ts:26](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L26)*
The amount to send The amount to send
...@@ -48,7 +49,7 @@ ___ ...@@ -48,7 +49,7 @@ ___
**blockHash**: *string* **blockHash**: *string*
*Defined in [src/balanceTransfer.ts:30](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L30)* *Defined in [src/balanceTransfer.ts:30](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L30)*
The checkpoint hash of the block, in hex The checkpoint hash of the block, in hex
...@@ -58,7 +59,7 @@ ___ ...@@ -58,7 +59,7 @@ ___
**blockNumber**: *number* **blockNumber**: *number*
*Defined in [src/balanceTransfer.ts:34](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L34)* *Defined in [src/balanceTransfer.ts:34](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L34)*
The checkpoint block number (u32), in hex The checkpoint block number (u32), in hex
...@@ -68,17 +69,27 @@ ___ ...@@ -68,17 +69,27 @@ ___
**genesisHash**: *string* **genesisHash**: *string*
*Defined in [src/balanceTransfer.ts:38](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L38)* *Defined in [src/balanceTransfer.ts:38](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L38)*
The genesis hash of the chain, in hex The genesis hash of the chain, in hex
___ ___
### `Optional` keepAlive
**keepAlive**? : *undefined | false | true*
*Defined in [src/balanceTransfer.ts:42](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L42)*
Use balances::transfer_keep_alive instead of balances::transfer
___
### metadataRpc ### metadataRpc
**metadataRpc**: *string* **metadataRpc**: *string*
*Defined in [src/balanceTransfer.ts:43](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L43)* *Defined in [src/balanceTransfer.ts:47](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L47)*
The SCALE-encoded metadata, as a hex string. Can be retrieved via the RPC The SCALE-encoded metadata, as a hex string. Can be retrieved via the RPC
call `state_getMetadata` call `state_getMetadata`
...@@ -89,7 +100,7 @@ ___ ...@@ -89,7 +100,7 @@ ___
**nonce**: *number* **nonce**: *number*
*Defined in [src/balanceTransfer.ts:47](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L47)* *Defined in [src/balanceTransfer.ts:51](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L51)*
The nonce for this transaction, The nonce for this transaction,
...@@ -99,7 +110,7 @@ ___ ...@@ -99,7 +110,7 @@ ___
**specVersion**: *number* **specVersion**: *number*
*Defined in [src/balanceTransfer.ts:51](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L51)* *Defined in [src/balanceTransfer.ts:55](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L55)*
The current spec version for the runtime The current spec version for the runtime
...@@ -109,7 +120,7 @@ ___ ...@@ -109,7 +120,7 @@ ___
**tip**: *number* **tip**: *number*
*Defined in [src/balanceTransfer.ts:55](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L55)* *Defined in [src/balanceTransfer.ts:59](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L59)*
The tip for this transaction, in hex The tip for this transaction, in hex
...@@ -119,7 +130,7 @@ ___ ...@@ -119,7 +130,7 @@ ___
**to**: *string* **to**: *string*
*Defined in [src/balanceTransfer.ts:59](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L59)* *Defined in [src/balanceTransfer.ts:63](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L63)*
The recipient address, ss-58 encoded The recipient address, ss-58 encoded
...@@ -129,7 +140,7 @@ ___ ...@@ -129,7 +140,7 @@ ___
**validityPeriod**: *number* **validityPeriod**: *number*
*Defined in [src/balanceTransfer.ts:64](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L64)* *Defined in [src/balanceTransfer.ts:68](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L68)*
The amount of time (in second) the transaction is valid for. Will be The amount of time (in second) the transaction is valid for. Will be
translated into a mortal era translated into a mortal era
...@@ -92,7 +92,7 @@ ___ ...@@ -92,7 +92,7 @@ ___
**metadataRpc**: *string* **metadataRpc**: *string*
*Defined in [src/balanceTransfer.ts:15](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L15)* *Defined in [src/balanceTransfer.ts:15](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L15)*
The SCALE-encoded metadata, as a hex string. Can be retrieved via the RPC The SCALE-encoded metadata, as a hex string. Can be retrieved via the RPC
call `state_getMetadata` call `state_getMetadata`
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
**BLOCKTIME**: *6* = 6 **BLOCKTIME**: *6* = 6
*Defined in [src/balanceTransfer.ts:68](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L68)* *Defined in [src/balanceTransfer.ts:72](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L72)*
___ ___
...@@ -32,7 +32,7 @@ ___ ...@@ -32,7 +32,7 @@ ___
**ONE_SECOND**: *number* = 1 / BLOCKTIME **ONE_SECOND**: *number* = 1 / BLOCKTIME
*Defined in [src/balanceTransfer.ts:69](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L69)* *Defined in [src/balanceTransfer.ts:73](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L73)*
## Functions ## Functions
...@@ -40,7 +40,7 @@ ___ ...@@ -40,7 +40,7 @@ ___
**balanceTransfer**(`info`: [TxInfo](../interfaces/_balancetransfer_.txinfo.md)): *[UnsignedTransaction](../interfaces/_balancetransfer_.unsignedtransaction.md)* **balanceTransfer**(`info`: [TxInfo](../interfaces/_balancetransfer_.txinfo.md)): *[UnsignedTransaction](../interfaces/_balancetransfer_.unsignedtransaction.md)*
*Defined in [src/balanceTransfer.ts:78](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/balanceTransfer.ts#L78)* *Defined in [src/balanceTransfer.ts:82](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/balanceTransfer.ts#L82)*
Construct a balance transfer transaction offline. Transactions can be Construct a balance transfer transaction offline. Transactions can be
constructed in such a way that it is valid for at least 240 minutes constructed in such a way that it is valid for at least 240 minutes
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
**createSignedTx**(`unsigned`: [UnsignedTransaction](../interfaces/_balancetransfer_.unsignedtransaction.md), `signature`: string): *string* **createSignedTx**(`unsigned`: [UnsignedTransaction](../interfaces/_balancetransfer_.unsignedtransaction.md), `signature`: string): *string*
*Defined in [src/createSignedTx.ts:14](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/createSignedTx.ts#L14)* *Defined in [src/createSignedTx.ts:14](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/createSignedTx.ts#L14)*
Serialize a signed transaction in a format that can be submitted over the Serialize a signed transaction in a format that can be submitted over the
Node RPC Interface from the signing payload and signature produced by the Node RPC Interface from the signing payload and signature produced by the
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
**createSigningPayload**(`unsigned`: [UnsignedTransaction](../interfaces/_balancetransfer_.unsignedtransaction.md)): *string* **createSigningPayload**(`unsigned`: [UnsignedTransaction](../interfaces/_balancetransfer_.unsignedtransaction.md)): *string*
*Defined in [src/createSigningPayload.ts:11](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/createSigningPayload.ts#L11)* *Defined in [src/createSigningPayload.ts:11](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/createSigningPayload.ts#L11)*
Construct the signing payload from an unsigned transaction and export it to Construct the signing payload from an unsigned transaction and export it to
a remote signer (this is often called "detached signing") a remote signer (this is often called "detached signing")
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
**decodeTx**(`signedTx`: string, `metadataRpc`: string): *Partial‹[TxInfo](../interfaces/_balancetransfer_.txinfo.md)›* **decodeTx**(`signedTx`: string, `metadataRpc`: string): *Partial‹[TxInfo](../interfaces/_balancetransfer_.txinfo.md)›*
*Defined in [src/decodeTx.ts:17](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/decodeTx.ts#L17)* *Defined in [src/decodeTx.ts:17](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/decodeTx.ts#L17)*
Parse the transaction information from an unsigned and signed transaction Parse the transaction information from an unsigned and signed transaction
offline offline
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
**deriveAddress**(`publicKey`: string | Uint8Array, `ss58Format`: number): *string* **deriveAddress**(`publicKey`: string | Uint8Array, `ss58Format`: number): *string*
*Defined in [src/deriveAddress.ts:11](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/deriveAddress.ts#L11)* *Defined in [src/deriveAddress.ts:11](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/deriveAddress.ts#L11)*
Derive an address from a cryptographic public key offline Derive an address from a cryptographic public key offline
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
**generateKeypair**(): *[KeyringPair](../interfaces/_generatekeypair_.keyringpair.md)* **generateKeypair**(): *[KeyringPair](../interfaces/_generatekeypair_.keyringpair.md)*
*Defined in [src/generateKeypair.ts:15](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/generateKeypair.ts#L15)* *Defined in [src/generateKeypair.ts:15](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/generateKeypair.ts#L15)*
Generate a valid public/private keypair offline Generate a valid public/private keypair offline
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
**EXTRINSIC_VERSION**: *4* = 4 **EXTRINSIC_VERSION**: *4* = 4
*Defined in [src/util/constants.ts:3](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/util/constants.ts#L3)* *Defined in [src/util/constants.ts:3](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/util/constants.ts#L3)*
___ ___
...@@ -23,4 +23,4 @@ ___ ...@@ -23,4 +23,4 @@ ___
**KUSAMA_SS58_FORMAT**: *2* = 2 **KUSAMA_SS58_FORMAT**: *2* = 2
*Defined in [src/util/constants.ts:1](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/6203cdc/src/util/constants.ts#L1)* *Defined in [src/util/constants.ts:1](https://github.com/amaurymartiny/polkadotjs-wrapper/blob/9e2988f/src/util/constants.ts#L1)*
...@@ -36,6 +36,10 @@ export interface TxInfo { ...@@ -36,6 +36,10 @@ export interface TxInfo {
* The genesis hash of the chain, in hex * The genesis hash of the chain, in hex
*/ */
genesisHash: string; genesisHash: string;
/**
* Use balances::transfer_keep_alive instead of balances::transfer
*/
keepAlive?: boolean;
/** /**
* The SCALE-encoded metadata, as a hex string. Can be retrieved via the RPC * The SCALE-encoded metadata, as a hex string. Can be retrieved via the RPC
* call `state_getMetadata` * call `state_getMetadata`
...@@ -79,7 +83,10 @@ export function balanceTransfer(info: TxInfo): UnsignedTransaction { ...@@ -79,7 +83,10 @@ export function balanceTransfer(info: TxInfo): UnsignedTransaction {
const registry = new TypeRegistry(); const registry = new TypeRegistry();
const metadata = new Metadata(registry, info.metadataRpc); const metadata = new Metadata(registry, info.metadataRpc);
const method = metadata.tx.balances.transfer(info.to, info.amount).toHex(); const transfer = info.keepAlive
? metadata.tx.balances.transferKeepAlivetransfer
: metadata.tx.balances.transfer;
const method = transfer(info.to, info.amount).toHex();
return { return {
address: info.address, address: info.address,
......
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