mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 04:41:43 +03:00
local trx generation test
This commit is contained in:
parent
b63358423c
commit
435b012a68
@ -54,6 +54,7 @@
|
||||
"axios": "^0.21.1",
|
||||
"browserify-zlib": "~0.1.4",
|
||||
"buffer": "^6.0.3",
|
||||
"bytebuffer": "^5.0.1",
|
||||
"console-browserify": "^1.1.0",
|
||||
"constants-browserify": "^1.0.0",
|
||||
"core-js": "3.6.4",
|
||||
|
@ -2,8 +2,10 @@
|
||||
// import '../../../shim';
|
||||
// import * as bitcoin from 'bitcoinjs-lib';
|
||||
|
||||
import { Client, cryptoUtils, utils } from '@hiveio/dhive';
|
||||
import { Client, cryptoUtils, utils, Types, Transaction } from '@hiveio/dhive';
|
||||
import { PrivateKey } from '@esteemapp/dhive';
|
||||
import bytebuffer from 'bytebuffer';
|
||||
import { createHash } from 'react-native-crypto';
|
||||
|
||||
import { Client as hsClient } from 'hivesigner';
|
||||
import Config from 'react-native-config';
|
||||
@ -55,6 +57,22 @@ export const checkClient = async () => {
|
||||
|
||||
checkClient();
|
||||
|
||||
const sha256 = (input: Buffer | string): Buffer => {
|
||||
return createHash('sha256').update(input).digest();
|
||||
};
|
||||
|
||||
export const generateTrxId = (transaction) => {
|
||||
const buffer = new bytebuffer(bytebuffer.DEFAULT_CAPACITY, bytebuffer.LITTLE_ENDIAN);
|
||||
try {
|
||||
Types.Transaction(buffer, transaction);
|
||||
} catch (cause) {
|
||||
console.warn('SerializationError', cause);
|
||||
}
|
||||
buffer.flip();
|
||||
const transactionData = Buffer.from(buffer.toBuffer());
|
||||
return sha256(transactionData).toString('hex').slice(0, 40); //CryptoJS.enc.Hex
|
||||
};
|
||||
|
||||
export const getDigitPinCode = (pin) => decryptKey(pin, Config.PIN_KEY);
|
||||
|
||||
export const getDynamicGlobalProperties = () => client.database.getDynamicGlobalProperties();
|
||||
@ -665,7 +683,7 @@ export const vote = async (account, pin, author, permlink, weight) => {
|
||||
console.log('Returning vote response');
|
||||
return resp;
|
||||
} catch (err) {
|
||||
console.warn('Failed to complete vote');
|
||||
console.warn('Failed to complete vote', err);
|
||||
}
|
||||
};
|
||||
|
||||
@ -712,7 +730,14 @@ const _vote = (currentAccount, pin, author, permlink, weight) => {
|
||||
client.broadcast
|
||||
.sendOperations(args, privateKey)
|
||||
.then((result) => {
|
||||
Alert.alert('dhive transaction id: ' + JSON.stringify(result));
|
||||
console.log(result);
|
||||
console.log(generateTrxId(result.tx));
|
||||
Alert.alert(
|
||||
'dhive transaction id: ' +
|
||||
JSON.stringify(result) +
|
||||
'localGen:' +
|
||||
generateTrxId(result.tx),
|
||||
);
|
||||
resolve(result);
|
||||
})
|
||||
.catch((err) => {
|
||||
|
@ -1173,7 +1173,7 @@
|
||||
|
||||
"@hiveio/dhive@ecency/dhive-test":
|
||||
version "1.0.1"
|
||||
resolved "https://codeload.github.com/ecency/dhive-test/tar.gz/8ecafed50308c562a40300cc081c96fa59c4e38a"
|
||||
resolved "https://codeload.github.com/ecency/dhive-test/tar.gz/7bcf3d51ed889d47e2a0ed747debc37099c03c6b"
|
||||
dependencies:
|
||||
bs58 "^4.0.1"
|
||||
bytebuffer "^5.0.1"
|
||||
|
Loading…
Reference in New Issue
Block a user