Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
txwrapper
Commits
0744bf01
Commit
0744bf01
authored
Dec 02, 2019
by
Amaury Martiny
Browse files
Refactor: No metadataRpc in createSignedTx
parent
b5b9c201
Changes
5
Show whitespace changes
Inline
Side-by-side
src/balanceTransfer.ts
View file @
0744bf01
...
...
@@ -7,7 +7,13 @@ import { EXTRINSIC_VERSION } from './util/constants';
/**
* 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
{
/**
...
...
@@ -80,6 +86,7 @@ export function balanceTransfer(info: TxInfo): UnsignedTransaction {
period
:
DEFAULT_MORTAL_LENGTH
}).
toHex
(),
genesisHash
:
info
.
genesisHash
,
metadataRpc
:
info
.
metadataRpc
,
method
,
nonce
:
createType
(
registry
,
'
Compact<Index>
'
,
info
.
nonce
).
toHex
(),
specVersion
:
createType
(
registry
,
'
u32
'
,
info
.
specVersion
).
toHex
(),
...
...
src/createSignedTx.spec.ts
View file @
0744bf01
import
{
balanceTransfer
}
from
'
./balanceTransfer
'
;
import
{
createSignedTx
}
from
'
./createSignedTx
'
;
import
{
createSigningPayload
}
from
'
./createSigningPayload
'
;
import
{
metadataRpc
,
signWithAlice
,
TEST_TX_INFO
}
from
'
./util/testUtil
'
;
import
{
signWithAlice
,
TEST_TX_INFO
}
from
'
./util/testUtil
'
;
describe
(
'
createSignedTx
'
,
()
=>
{
it
(
'
should work
'
,
async
done
=>
{
...
...
@@ -9,7 +9,7 @@ describe('createSignedTx', () => {
const
signingPayload
=
createSigningPayload
(
unsigned
);
const
signature
=
await
signWithAlice
(
signingPayload
);
const
tx
=
createSignedTx
(
unsigned
,
signature
,
metadataRpc
);
const
tx
=
createSignedTx
(
unsigned
,
signature
);
expect
(
tx
).
toBe
(
'
0x2d0284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d003d0fdf8b55e6712b2766d80e9a4f527c3deb3d728a815db77df52d766643cdab3170e25ccd867a4d16c0a8f648b753cd95fed0b46ace6cc4e6e5942712409908eb5808000600ff96074594cccf1cd185fa8a72ceaeefd86648f8d45514f3ce33c31bdd07e4655d30
'
);
...
...
src/createSignedTx.ts
View file @
0744bf01
...
...
@@ -14,11 +14,10 @@ import { UnsignedTransaction } from './balanceTransfer';
*/
export
function
createSignedTx
(
unsigned
:
UnsignedTransaction
,
signature
:
string
,
metadataRpc
:
string
signature
:
string
):
string
{
const
registry
=
new
TypeRegistry
();
registry
.
setMetadata
(
new
Metadata
(
registry
,
metadataRpc
));
registry
.
setMetadata
(
new
Metadata
(
registry
,
unsigned
.
metadataRpc
));
const
extrinsic
=
createType
(
registry
,
...
...
src/decodeTx.spec.ts
View file @
0744bf01
...
...
@@ -2,7 +2,7 @@ import { balanceTransfer } from './balanceTransfer';
import
{
createSignedTx
}
from
'
./createSignedTx
'
;
import
{
createSigningPayload
}
from
'
./createSigningPayload
'
;
import
{
decodeTx
}
from
'
./decodeTx
'
;
import
{
metadataRpc
,
signWithAlice
,
TEST_TX_INFO
}
from
'
./util/testUtil
'
;
import
{
signWithAlice
,
TEST_TX_INFO
}
from
'
./util/testUtil
'
;
describe
(
'
decodeTx
'
,
()
=>
{
it
(
'
should work
'
,
async
done
=>
{
...
...
@@ -10,9 +10,9 @@ describe('decodeTx', () => {
const
signingPayload
=
createSigningPayload
(
unsigned
);
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
=>
expect
(
txInfo
[
key
]).
toBe
(
TEST_TX_INFO
[
key
])
...
...
src/util/testUtil.ts
View file @
0744bf01
...
...
@@ -6,8 +6,6 @@ import { cryptoWaitReady } from '@polkadot/util-crypto';
import
{
TxInfo
}
from
'
../balanceTransfer
'
;
export
{
metadataRpc
};
/**
* @ignore
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment