mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 21:01:31 +03:00
local broadcast tx generation
This commit is contained in:
parent
435b012a68
commit
51d638c1b5
@ -35,7 +35,7 @@
|
||||
"@esteemapp/react-native-multi-slider": "^1.1.0",
|
||||
"@esteemapp/react-native-render-html": "^4.1.5",
|
||||
"@esteemapp/react-native-slider": "^0.12.0",
|
||||
"@hiveio/dhive": "ecency/dhive-test",
|
||||
"@hiveio/dhive": "^1.0.1",
|
||||
"@react-native-community/async-storage": "^1.11.0",
|
||||
"@react-native-community/cameraroll": "^1.3.0",
|
||||
"@react-native-community/cli-platform-ios": "^4.10.1",
|
||||
|
@ -2,7 +2,15 @@
|
||||
// import '../../../shim';
|
||||
// import * as bitcoin from 'bitcoinjs-lib';
|
||||
|
||||
import { Client, cryptoUtils, utils, Types, Transaction } from '@hiveio/dhive';
|
||||
import {
|
||||
Client,
|
||||
cryptoUtils,
|
||||
utils,
|
||||
Types,
|
||||
Transaction,
|
||||
Operation,
|
||||
TransactionConfirmation,
|
||||
} from '@hiveio/dhive';
|
||||
import { PrivateKey } from '@esteemapp/dhive';
|
||||
import bytebuffer from 'bytebuffer';
|
||||
import { createHash } from 'react-native-crypto';
|
||||
@ -73,6 +81,38 @@ export const generateTrxId = (transaction) => {
|
||||
return sha256(transactionData).toString('hex').slice(0, 40); //CryptoJS.enc.Hex
|
||||
};
|
||||
|
||||
export const sendHiveOperations = async (
|
||||
operations: Operation[],
|
||||
key: PrivateKey | PrivateKey[],
|
||||
): Promise<TransactionConfirmation> => {
|
||||
const { head_block_number, head_block_id, time } = await getDynamicGlobalProperties();
|
||||
const ref_block_num = head_block_number & 0xffff;
|
||||
const ref_block_prefix = Buffer.from(head_block_id, 'hex').readUInt32LE(4);
|
||||
const expireTime = 60 * 1000;
|
||||
const chainId = Buffer.from(
|
||||
'beeab0de00000000000000000000000000000000000000000000000000000000',
|
||||
'hex',
|
||||
);
|
||||
const expiration = new Date(new Date(time + 'Z').getTime() + expireTime)
|
||||
.toISOString()
|
||||
.slice(0, -5);
|
||||
const extensions = [];
|
||||
|
||||
const tx: Transaction = {
|
||||
expiration: expiration,
|
||||
extensions: extensions,
|
||||
operations: operations,
|
||||
ref_block_num: ref_block_num,
|
||||
ref_block_prefix: ref_block_prefix,
|
||||
};
|
||||
|
||||
const transaction = await cryptoUtils.signTransaction(tx, key, chainId);
|
||||
const trxId = generateTrxId(transaction);
|
||||
const resultHive = await client.broadcast.call('broadcast_transaction', [transaction]);
|
||||
const result = Object.assign({ id: trxId }, resultHive);
|
||||
return result;
|
||||
};
|
||||
|
||||
export const getDigitPinCode = (pin) => decryptKey(pin, Config.PIN_KEY);
|
||||
|
||||
export const getDynamicGlobalProperties = () => client.database.getDynamicGlobalProperties();
|
||||
@ -727,17 +767,9 @@ const _vote = (currentAccount, pin, author, permlink, weight) => {
|
||||
];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
client.broadcast
|
||||
.sendOperations(args, privateKey)
|
||||
sendHiveOperations(args, privateKey)
|
||||
.then((result) => {
|
||||
console.log(result);
|
||||
console.log(generateTrxId(result.tx));
|
||||
Alert.alert(
|
||||
'dhive transaction id: ' +
|
||||
JSON.stringify(result) +
|
||||
'localGen:' +
|
||||
generateTrxId(result.tx),
|
||||
);
|
||||
console.log('vote result', result);
|
||||
resolve(result);
|
||||
})
|
||||
.catch((err) => {
|
||||
|
@ -1171,9 +1171,10 @@
|
||||
dependencies:
|
||||
"@hapi/hoek" "^8.3.0"
|
||||
|
||||
"@hiveio/dhive@ecency/dhive-test":
|
||||
"@hiveio/dhive@^1.0.1":
|
||||
version "1.0.1"
|
||||
resolved "https://codeload.github.com/ecency/dhive-test/tar.gz/7bcf3d51ed889d47e2a0ed747debc37099c03c6b"
|
||||
resolved "https://registry.yarnpkg.com/@hiveio/dhive/-/dhive-1.0.1.tgz#76bb9e9dbd4cc9efadafd8a40b7025c997a56aba"
|
||||
integrity sha512-j6PEAhLwhSWzMjQiPS0Qsy3jZ+6pAirlnPkgkkb+3q7CGG0eNA7w5VYaFv4OFGecOQfESj7MViYhpzC+5qiq0Q==
|
||||
dependencies:
|
||||
bs58 "^4.0.1"
|
||||
bytebuffer "^5.0.1"
|
||||
|
Loading…
Reference in New Issue
Block a user