Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
chore: update to DAPI Client 0.16 (#197)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: replaced Transport#getIdentityIdByFirstPublicKey(string): string with Transport#getIdentityIdsByPublicKeyHash(Buffer[]): Buffer[]

Co-authored-by: Konstantin Shuplenkov <konstantin.shuplenkov@dash.org>
Co-authored-by: Ivan Shumkov <ivan@shumkov.ru>
  • Loading branch information
3 people authored Oct 21, 2020
1 parent b18e764 commit 6cae0ab
Show file tree
Hide file tree
Showing 30 changed files with 1,316 additions and 1,908 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ before_script:
script: npm run check-package && npm run lint && npm run test

before_deploy:
# Add token for @dashevo private npm registry & deployement
# Add token for @dashevo private npm registry & deployment
- echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc

deploy:
Expand Down
1 change: 0 additions & 1 deletion examples/wallet-fromHDPubKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const wallet = new Wallet({
network: 'testnet',
});


wallet.getAccount()
.then(async (account) => {
logger.info('Balance Confirmed', await account.getConfirmedBalance(false));
Expand Down
1 change: 0 additions & 1 deletion examples/wallet-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const wallet = new Wallet({
plugins: [WalletConsolidator, new ColdStorageWorker({ address: coldStorageAddress })],
});


wallet.getAccount({ index: 0 })
.then((account) => {
const showcasePlugin = async () => {
Expand Down
3,143 changes: 1,282 additions & 1,861 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
},
"homepage": "https://github.com/dashevo/wallet-lib#readme",
"dependencies": {
"@dashevo/dapi-client": "~0.16.0-dev.3",
"@dashevo/dashcore-lib": "~0.18.12",
"@dashevo/dpp": "~0.16.0-dev.6",
"@dashevo/dapi-client": "~0.16.0-dev.8",
"@dashevo/dashcore-lib": "~0.18.13",
"@dashevo/dpp": "~0.16.0-dev.9",
"@dashevo/grpc-common": "~0.3.1",
"cbor": "^5.0.2",
"crypto-js": "^4.0.0",
Expand Down
1 change: 0 additions & 1 deletion src/errors/InvalidDashcoreTransaction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const WalletLibError = require('./WalletLibError');


class InvalidDashcoreTransaction extends WalletLibError {
constructor(tx, reason = 'A Dashcore Transaction object or valid rawTransaction is required') {
super(`${reason}: ${tx.toString()}`);
Expand Down
1 change: 0 additions & 1 deletion src/errors/InvalidRawTransaction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const WalletLibError = require('./WalletLibError');


class InvalidTransaction extends WalletLibError {
constructor() {
super('A valid transaction object or it\'s hex representation is required');
Expand Down
1 change: 0 additions & 1 deletion src/errors/InvalidTransactionObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const is = require('../utils/is');

const WalletLibError = require('./WalletLibError');


class InvalidTransactionObject extends WalletLibError {
constructor(transactionObj) {
const getErrorMessageOf = (transactionErrors) => {
Expand Down
2 changes: 0 additions & 2 deletions src/errors/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const CreateTransactionError = require('./CreateTransactionError');
const CoinSelectionUnsufficientUTXOS = require('./CoinSelectionUnsufficientUTXOS');
const InjectionErrorCannotInject = require('./InjectionErrorCannotInject');
Expand Down Expand Up @@ -31,7 +30,6 @@ const WalletLibError = require('./WalletLibError');

const PluginInjectionError = require('./PluginInjectionError');


module.exports = {
BlockHeaderNotInStore,
CreateTransactionError,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/Plugins/ChainPlugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const logger = require('../../logger');
const { StandardPlugin } = require('../');
const { StandardPlugin } = require('..');
const EVENTS = require('../../EVENTS');

const defaultOpts = {
Expand Down
16 changes: 14 additions & 2 deletions src/plugins/Workers/IdentitySyncWorker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Identifier = require('@dashevo/dpp/lib/Identifier');
const Worker = require('../Worker');

const logger = require('../../logger');
Expand Down Expand Up @@ -63,7 +64,7 @@ class IdentitySyncWorker extends Worker {
const publicKey = privateKey.toPublicKey();

// eslint-disable-next-line no-await-in-loop
const fetchedId = await this.transport.getIdentityIdByFirstPublicKey(publicKey.hash);
const [fetchedId] = await this.transport.getIdentityIdsByPublicKeyHash([publicKey.hash]);

// if identity id is not preset then increment gap count
// and stop sync if gap limit is reached
Expand All @@ -82,14 +83,25 @@ class IdentitySyncWorker extends Worker {
continue;
}

// If it's not a null and not a buffer or Identifier (which inherits Buffer),
// this method will loop forever.
// This check prevents this from happening
if (!Buffer.isBuffer(fetchedId)) {
throw new Error(`Expected identity id to be a Buffer or null, got ${fetchedId}`);
}

// reset gap counter if we got an identity
// it means gaps are not sequential
gapCount = 0;

logger.silly(`IdentitySyncWorker - got ${fetchedId} at ${index}`);

// eslint-disable-next-line no-await-in-loop
await this.storage.insertIdentityIdAtIndex(this.walletId, fetchedId, index);
await this.storage.insertIdentityIdAtIndex(
this.walletId,
Identifier.from(fetchedId).toString(),
index,
);
}

logger.silly('IdentitySyncWorker - sync finished');
Expand Down
2 changes: 1 addition & 1 deletion src/transport/DAPIClientTransport/DAPIClientTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ DAPIClientTransport.prototype.getTransaction = require('./methods/getTransaction
DAPIClientTransport.prototype.sendTransaction = require('./methods/sendTransaction');
DAPIClientTransport.prototype.subscribeToBlockHeaders = require('./methods/subscribeToBlockHeaders');
DAPIClientTransport.prototype.subscribeToBlocks = require('./methods/subscribeToBlocks');
DAPIClientTransport.prototype.getIdentityIdByFirstPublicKey = require('./methods/getIdentityIdByFirstPublicKey');
DAPIClientTransport.prototype.getIdentityIdsByPublicKeyHash = require('./methods/getIdentityIdsByPublicKeyHashes');
DAPIClientTransport.prototype.subscribeToTransactionsWithProofs = require('./methods/subscribeToTransactionsWithProofs');

module.exports = DAPIClientTransport;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const logger = require('../../../logger');

/**
* @param {Buffer[]} publicKeyHashes
* @return {Promise<*|string>}
*/
module.exports = async function getIdentityIdsByPublicKeyHashes(publicKeyHashes) {
logger.silly('DAPIClientTransport.getIdentityIdsByPublicKeyHashes');

return this.client.platform.getIdentityIdsByPublicKeyHashes(
publicKeyHashes,
);
};
1 change: 0 additions & 1 deletion src/transport/FixtureTransport/data/blocks/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const heights = {
21638: '00000011eb4dfa5034e1dd16c46e1a14b74c403a62c6fb61abccf72edd42b9d3',
};


const hashes = Object.entries(heights).reduce((obj, [height, hash]) => {
// eslint-disable-next-line no-param-reassign
obj[hash] = height;
Expand Down
1 change: 0 additions & 1 deletion src/transport/FixtureTransport/methods/getBestBlockHash.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

module.exports = async function getBestBlockHash() {
return this.blockHash;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

module.exports = async function getBestBlockHeight() {
return this.height;
};
2 changes: 1 addition & 1 deletion src/transport/Transport.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export declare interface Transport {

getBlockHeaderByHeight(height): Promise<BlockHeader>

getIdentityIdByFirstPublicKey(publicKeyHash): Promise<string>
getIdentityIdsByPublicKeyHash(publicKeyHashes: Buffer[]): Promise<Buffer[]>

getStatus(): Promise<object>

Expand Down
1 change: 0 additions & 1 deletion src/types/Account/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class Account extends EventEmitter {
this.walletType = wallet.walletType;
this.offlineMode = wallet.offlineMode;


this.index = _.has(opts, 'index') ? opts.index : getNextUnusedAccountIndexForWallet(wallet);
this.strategy = _loadStrategy(_.has(opts, 'strategy') ? opts.strategy : defaultOptions.strategy);
this.network = getNetwork(wallet.network).toString();
Expand Down
1 change: 0 additions & 1 deletion src/types/Account/_loadStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ const _loadStrategy = function _loadStrategy(arg) {
throw new InvalidStrategy(arg);
};


module.exports = _loadStrategy;
3 changes: 0 additions & 3 deletions src/types/Account/methods/createTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function createTransaction(opts = {}) {
outputs = [{ address: opts.recipient, satoshis }];
}


const deductFee = _.has(opts, 'deductFee')
? opts.deductFee
: true;
Expand All @@ -64,7 +63,6 @@ function createTransaction(opts = {}) {
? _loadStrategy(opts.strategy)
: this.strategy;


const utxosList = _.has(opts, 'utxos') ? parseUtxos(opts.utxos) : this.getUTXOS();

const feeCategory = (opts.isInstantSend) ? 'instant' : 'normal';
Expand All @@ -77,7 +75,6 @@ function createTransaction(opts = {}) {

const selectedUTXOs = selection.utxos;


const selectedOutputs = selection.outputs;
const {
// feeCategory,
Expand Down
2 changes: 0 additions & 2 deletions src/types/Account/methods/getTransactionHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ async function getTransactionHistory() {
}
});


_.each(tx.vin, (vin) => {
if (vin.addr) {
const address = vin.addr;
Expand Down Expand Up @@ -226,7 +225,6 @@ async function getTransactionHistory() {
// When the account is sender of an inbetween account movement
type = 'moved_account';


if (nbOfOtherAccountVout > 0) {
_.each(meta.vout.otherAccount, (el) => {
considerValue(to, el.address, (parseFloat(el.valueSat)));
Expand Down
1 change: 0 additions & 1 deletion src/types/Storage/methods/importBlockHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const importBlockHeader = function importBlockHeader(blockHeader, height) {
const chainStore = store.chains[network];
const { blockHeight: currentChainHeight } = store.chains[network];


if (!chainStore.blockHeaders[blockHeader.hash]) {
if (height) {
if (height > currentChainHeight) store.chains[network].blockHeight = height;
Expand Down
2 changes: 0 additions & 2 deletions src/types/Storage/methods/importTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ const importTransaction = function importTransaction(transaction) {
let outputIndex = -1;
const processedAddressesForTx = {};


// If we already had this transaction locally, we won't add it again,
// but we still need to continue processing it as we might have new
// address generated (on BIP44 wallets) since the first checkup.
if (!transactions[transaction.hash]) {
transactions[transaction.hash] = transaction;
}


[...inputs, ...outputs].forEach((element) => {
const isOutput = (element instanceof Output);
if (isOutput) outputIndex += 1;
Expand Down
1 change: 0 additions & 1 deletion src/types/Storage/methods/searchAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const searchAddress = function searchAddress(address, forceLoop = false) {
search.walletId = walletId;
}


return search;
};
module.exports = searchAddress;
1 change: 0 additions & 1 deletion src/types/Storage/methods/updateAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const updateAddress = function updateAddress(addressObj, walletId) {
});
}


// Check if there is a balance but no utxo.
addressesStore[type][path] = newObject;
if (previousObject === undefined) {
Expand Down
1 change: 0 additions & 1 deletion src/types/Wallet/methods/fromHDPublicKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { is } = require('../../../utils');
const KeyChain = require('../../KeyChain/KeyChain');
const { WALLET_TYPES } = require('../../../CONSTANTS');


const normalizeHDPubKey = (key) => (is.string(key) ? Dashcore.HDPublicKey(key) : key);
/**
* Will set a wallet to work with a on readonly mode from a HDPublicKey
Expand Down
1 change: 0 additions & 1 deletion src/types/Wallet/methods/fromPrivateKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { is } = require('../../../utils');
const KeyChain = require('../../KeyChain/KeyChain');
const { WALLET_TYPES } = require('../../../CONSTANTS');


/**
* Will set a wallet to work with a mnemonic (keychain, walletType & HDPrivateKey)
* @param privateKey
Expand Down
1 change: 0 additions & 1 deletion src/utils/bip44/ensureAddressesToGapLimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function ensureAccountAddressesToGapLimit(walletStore, walletType, accountIndex,
// Ensure that all our above external paths are contiguous
const missingIndexes = getMissingIndexes(externalAddressesPaths);


// Gets missing addresses and adds them to the storage
// Please note that getAddress adds new addresses to storage, which it probably shouldn't
missingIndexes.forEach((index) => {
Expand Down
1 change: 0 additions & 1 deletion src/utils/coinSelections/helpers/sortAndVerifyUTXOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const sort = {
return 0;
});


return el;
},
};
Expand Down

0 comments on commit 6cae0ab

Please sign in to comment.