Encoding works as expected

This commit is contained in:
Jaco Greeff 2018-04-18 17:45:35 +02:00
parent ddd4a0c3ff
commit 0e2b6b9a8e
6 changed files with 15 additions and 19 deletions

View File

@ -12,7 +12,10 @@ import Button from 'semantic-ui-react/dist/es/elements/Button';
import withObservable from '@polkadot/rx-react/with/observable';
import StakingTransfer from '../StakingTransfer';
import encode from '../encode';
import addrSender from '../subject/addrSender';
import extrinsicName from '../subject/extrinsicName';
import nonceSender from '../subject/nonceSender';
import ErrorComponent from './Error';
type Props = BaseProps & {
@ -30,7 +33,7 @@ function CallDisplay ({ className, style, value }: Props) {
const Component = COMPONENTS[value] || ErrorComponent;
const onSubmit = () => {
console.log('getValues', Component.getValues());
encode(addrSender.getValue(), nonceSender.getValue(), value, Component.getValues());
};
return (

View File

@ -8,7 +8,7 @@ import addrRecipient from '../subject/addrRecipient';
export default function getValues (): Array<mixed> {
return [
addrRecipient.getValue(),
addrRecipient.getValue().publicKey(),
amount.getValue()
];
}

View File

@ -3,8 +3,9 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import BN from 'bn.js';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
const subject = new BehaviorSubject();
const subject = new BehaviorSubject(new BN(0));
export default subject;

View File

@ -6,16 +6,16 @@
// TODO: Move to API
import type BN from 'bn.js';
import type { Call } from '../calls/types';
const bnToU8a = require('@polkadot/util/bn/toU8a');
const u8aConcat = require('@polkadot/util/u8a/concat');
const u8aToHex = require('@polkadot/util/u8a/toHex');
const calls = require('../calls');
const encodeParams = require('./params');
// flowlint-next-line unclear-type:off
module.exports = function encode (sender: KeyringPair, nonce: number | BN, { index, params }: Call, values: Array<mixed>) {
module.exports = function encode (sender: KeyringPair, nonce: number | BN, method: string, values: Array<mixed>): Uint8Array {
const { index, params } = calls[method];
const encodedParams = encodeParams(values, params);
const message = u8aConcat(
sender.publicKey(),
@ -25,11 +25,5 @@ module.exports = function encode (sender: KeyringPair, nonce: number | BN, { ind
);
const signature = sender.sign(message);
console.log('message', u8aToHex(message));
console.log('signature', u8aToHex(signature));
return {
message,
signature
};
return u8aConcat(message, signature);
};

View File

@ -3,8 +3,8 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
const subject = new ReplaySubject(1);
const subject = new BehaviorSubject();
export default subject;

View File

@ -4,10 +4,8 @@
// @flow
import BN from 'bn.js';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
const subject = new ReplaySubject(1);
subject.next(new BN(0));
const subject = new BehaviorSubject(new BN(0));
export default subject;