Skip to content

Commit

Permalink
[FEAT] Litecoin Support
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbazan7 committed Jul 6, 2021
1 parent d0470bd commit 17fdf7a
Show file tree
Hide file tree
Showing 29 changed files with 176 additions and 57 deletions.
8 changes: 7 additions & 1 deletion packages/bitcore-node/src/modules/ethereum/api/csp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,13 @@ export class ETHStateProvider extends InternalStateProvider implements IChainSta
{ chain, network, from: { $in: addressBatch } },
{ chain, network, to: { $in: addressBatch } },
{ chain, network, 'internal.action.to': { $in: addressBatch } },
{ chain, network, 'abiType.params.0.value': { $in: addressBatch.map(address => address.toLowerCase()) }, 'abiType.type': 'ERC20', 'abiType.name': 'transfer' }
{
chain,
network,
'abiType.params.0.value': { $in: addressBatch.map(address => address.toLowerCase()) },
'abiType.type': 'ERC20',
'abiType.name': 'transfer'
}
]
},
{ $addToSet: { wallets: params.wallet._id } }
Expand Down
23 changes: 12 additions & 11 deletions packages/bitcore-wallet-client/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var Bitcore_ = {
bch: CWC.BitcoreLibCash,
eth: CWC.BitcoreLib,
xrp: CWC.BitcoreLib,
doge: CWC.BitcoreLibDoge
doge: CWC.BitcoreLibDoge,
ltc: CWC.BitcoreLibLtc
};
var Mnemonic = require('bitcore-mnemonic');
var url = require('url');
Expand Down Expand Up @@ -68,6 +69,7 @@ export class API extends EventEmitter {
static Bitcore = CWC.BitcoreLib;
static BitcoreCash = CWC.BitcoreLibCash;
static BitcoreDoge = CWC.BitcoreLibDoge;
static BitcoreLtc = CWC.BitcoreLibLtc;

constructor(opts?) {
super();
Expand Down Expand Up @@ -2840,9 +2842,8 @@ export class API extends EventEmitter {
return;
}
log.info(`Importing token: ${token.name}`);
const tokenCredentials = client.credentials.getTokenCredentials(
token
);
const tokenCredentials =
client.credentials.getTokenCredentials(token);
let tokenClient = _.cloneDeep(client);
tokenClient.credentials = tokenCredentials;
clients.push(tokenClient);
Expand All @@ -2855,14 +2856,13 @@ export class API extends EventEmitter {
log.info(
`Importing multisig wallet. Address: ${info.multisigContractAddress} - m: ${info.m} - n: ${info.n}`
);
const multisigEthCredentials = client.credentials.getMultisigEthCredentials(
{
const multisigEthCredentials =
client.credentials.getMultisigEthCredentials({
walletName: info.walletName,
multisigContractAddress: info.multisigContractAddress,
n: info.n,
m: info.m
}
);
});
let multisigEthClient = _.cloneDeep(client);
multisigEthClient.credentials = multisigEthCredentials;
clients.push(multisigEthClient);
Expand All @@ -2875,9 +2875,8 @@ export class API extends EventEmitter {
return;
}
log.info(`Importing multisig token: ${token.name}`);
const tokenCredentials = multisigEthClient.credentials.getTokenCredentials(
token
);
const tokenCredentials =
multisigEthClient.credentials.getTokenCredentials(token);
let tokenClient = _.cloneDeep(multisigEthClient);
tokenClient.credentials = tokenCredentials;
clients.push(tokenClient);
Expand Down Expand Up @@ -2909,6 +2908,8 @@ export class API extends EventEmitter {
['xrp', 'testnet'],
['doge', 'livenet'],
['doge', 'testnet'],
['ltc', 'testnet'],
['ltc', 'livenet'],
['btc', 'livenet', true],
['bch', 'livenet', true]
];
Expand Down
3 changes: 2 additions & 1 deletion packages/bitcore-wallet-client/src/lib/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const Constants = {
'eth',
'xrp',
'doge',
'ltc',
'usdc',
'pax',
'gusd',
Expand All @@ -35,7 +36,7 @@ export const Constants = {
'wbtc'
],
ERC20: ['usdc', 'pax', 'gusd', 'busd', 'dai', 'wbtc'],
UTXO_COINS: ['btc', 'bch', 'doge'],
UTXO_COINS: ['btc', 'bch', 'doge', 'ltc'],
TOKEN_OPTS: CWC.Constants.TOKEN_OPTS,
UNITS: CWC.Constants.UNITS
};
4 changes: 3 additions & 1 deletion packages/bitcore-wallet-client/src/lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
BitcoreLib,
BitcoreLibCash,
BitcoreLibDoge,
BitcoreLibLtc,
Deriver,
Transactions
} from 'crypto-wallet-core';
Expand All @@ -22,7 +23,8 @@ const Bitcore_ = {
bch: BitcoreLibCash,
eth: Bitcore,
xrp: Bitcore,
doge: BitcoreLibDoge
doge: BitcoreLibDoge,
ltc: BitcoreLibLtc
};
const PrivateKey = Bitcore.PrivateKey;
const PublicKey = Bitcore.PublicKey;
Expand Down
7 changes: 6 additions & 1 deletion packages/bitcore-wallet-client/src/lib/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ export class Credentials {
coin = '144';
} else if (this.coin == 'doge') {
coin = '3';
} else if (this.coin == 'ltc') {
coin = '2';
} else {
throw new Error('unknown coin: ' + this.coin);
}
Expand Down Expand Up @@ -309,7 +311,10 @@ export class Credentials {
isComplete() {
if (!this.m || !this.n) return false;
if (
(this.coin === 'btc' || this.coin === 'bch' || this.coin === 'doge') &&
(this.coin === 'btc' ||
this.coin === 'bch' ||
this.coin === 'doge' ||
this.coin === 'ltc') &&
(!this.publicKeyRing || this.publicKeyRing.length != this.n)
)
return false;
Expand Down
2 changes: 2 additions & 0 deletions packages/bitcore-wallet-client/src/lib/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ export class Key {
coinCode = '144';
} else if (opts.coin == 'doge') {
coinCode = '3';
} else if (opts.coin == 'ltc') {
coinCode = '2';
} else {
throw new Error('unknown coin: ' + opts.coin);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/bitcore-wallet-client/src/lib/payproV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var MAX_FEE_PER_KB = {
bch: 10000 * 1000, // 10k sat/b
eth: 1000000000000, // 1000 Gwei
xrp: 1000000000000,
doge: 10000 * 1000 // 10k sat/b
doge: 10000 * 1000, // 10k sat/b
ltc: 10000 * 1000 // 10k sat/b
};

// PayPro Network Map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ Promise.all(keyRequests)
}
signatureCount++;
console.log(
`Good signature from ${
signature.identifier
} (${pgpKey.get_userids()[0].get_username()})`
`Good signature from ${signature.identifier} (${pgpKey
.get_userids()[0]
.get_username()})`
);
return Promise.resolve();
}
Expand Down
1 change: 1 addition & 0 deletions packages/bitcore-wallet-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"bitcore-lib": "^8.25.10",
"bitcore-lib-cash": "^8.25.10",
"bitcore-lib-doge": "^8.25.10",
"bitcore-lib-ltc": "^8.25.12",
"body-parser": "^1.11.0",
"compression": "^1.6.2",
"crypto-wallet-core": "^8.25.12",
Expand Down
12 changes: 12 additions & 0 deletions packages/bitcore-wallet-service/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ module.exports = {
url: 'https://api.bitcore.io'
}
},
ltc: {
livenet: {
url: 'https://api.bitcore.io'
},
testnet: {
url: 'https://api.bitcore.io'
}
},
socketApiKey: 'socketApiKey'
},
pushNotificationsOpts: {
Expand Down Expand Up @@ -158,6 +166,10 @@ module.exports = {
// doge: {
// livenet: 'https://blockchair.com/dogecoin/transaction/{{txid}}',
// testnet: 'https://sochain.com/tx/DOGETEST/{{txid}}',
// },
// ltc: {
// livenet: 'https://bitpay.com/insight/#/LTC/mainnet/tx/{{txid}}',
// testnet: 'https://bitpay.com/insight/#/LTC/testnet/tx/{{txid}}',
// }
// },
// },
Expand Down
4 changes: 4 additions & 0 deletions packages/bitcore-wallet-service/src/lib/blockchainexplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const PROVIDERS = {
doge: {
livenet: 'https://api.bitpay.com',
testnet: 'https://api.bitpay.com'
},
ltc: {
livenet: 'https://api.bitpay.com',
testnet: 'https://api.bitpay.com'
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const Bitcore_ = {
bch: require('bitcore-lib-cash'),
eth: Bitcore,
xrp: Bitcore,
doge: require('bitcore-lib-doge')
doge: require('bitcore-lib-doge'),
ltc: require('bitcore-lib-ltc')
};
const config = require('../../config');
const Constants = Common.Constants,
Expand Down
3 changes: 2 additions & 1 deletion packages/bitcore-wallet-service/src/lib/blockchainmonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export class BlockchainMonitor {
bch: {},
eth: {},
xrp: {},
doge: {}
doge: {},
ltc: {}
};

const coinNetworkPairs = [];
Expand Down
4 changes: 3 additions & 1 deletion packages/bitcore-wallet-service/src/lib/chain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BchChain } from './bch';
import { BtcChain } from './btc';
import { DogeChain } from './doge';
import { EthChain } from './eth';
import { LtcChain } from './ltc';
import { XrpChain } from './xrp';

const Common = require('../common');
Expand Down Expand Up @@ -70,7 +71,8 @@ const chain: { [chain: string]: IChain } = {
BCH: new BchChain(),
ETH: new EthChain(),
XRP: new XrpChain(),
DOGE: new DogeChain()
DOGE: new DogeChain(),
LTC: new LtcChain()
};

class ChainProxy {
Expand Down
10 changes: 10 additions & 0 deletions packages/bitcore-wallet-service/src/lib/chain/ltc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BitcoreLibLtc } from 'crypto-wallet-core';
import _ from 'lodash';
import { IChain } from '..';
import { BtcChain } from '../btc';

export class LtcChain extends BtcChain implements IChain {
constructor() {
super(BitcoreLibLtc);
}
}
4 changes: 3 additions & 1 deletion packages/bitcore-wallet-service/src/lib/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
ETH: 'eth',
XRP: 'xrp',
DOGE: 'doge',
LTC: 'ltc',
USDC: 'usdc',
PAX: 'pax',
GUSD: 'gusd',
Expand All @@ -28,7 +29,8 @@ module.exports = {
UTXO_COINS: {
BTC: 'btc',
BCH: 'bch',
DOGE: 'doge'
DOGE: 'doge',
LTC: 'ltc'
},

NETWORKS: {
Expand Down
16 changes: 13 additions & 3 deletions packages/bitcore-wallet-service/src/lib/common/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ module.exports = {
nbBlocks: 2,
defaultValue: 100000000
}
],
ltc: [
{
name: 'normal',
nbBlocks: 2,
defaultValue: 1000
}
]
},

Expand Down Expand Up @@ -211,23 +218,26 @@ module.exports = {
bch: 10000 * 1000, // 10k sat/b
eth: 1000000000000, // 50 Gwei,
xrp: 1000000000000,
doge: 100000000 * 100
doge: 100000000 * 100,
ltc: 10000 * 1000 // 10k sat/b
},

MIN_TX_FEE: {
btc: 0,
bch: 0,
eth: 0,
xrp: 0,
doge: 0
doge: 0,
ltc: 0
},

MAX_TX_FEE: {
btc: 0.05 * 1e8,
bch: 0.05 * 1e8,
eth: 1 * 1e18, // 1 eth
xrp: 1 * 1e6, // 1 xrp
doge: 400 * 1e8
doge: 400 * 1e8,
ltc: 0.05 * 1e8
},

// ETH
Expand Down
10 changes: 8 additions & 2 deletions packages/bitcore-wallet-service/src/lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const Bitcore = require('bitcore-lib');
const Bitcore_ = {
btc: Bitcore,
bch: require('bitcore-lib-cash'),
doge: require('bitcore-lib-doge')
doge: require('bitcore-lib-doge'),
ltc: require('bitcore-lib-ltc')
};

export class Utils {
Expand Down Expand Up @@ -244,7 +245,12 @@ export class Utils {
new Bitcore_['doge'].Address(address);
return 'doge';
} catch (e) {
return;
try {
new Bitcore_['ltc'].Address(address);
return 'ltc';
} catch (e) {
return;
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/bitcore-wallet-service/src/lib/emailservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ export class EmailService {
bch: 'BCH',
eth: 'ETH',
xrp: 'XRP',
doge: 'DOGE'
doge: 'DOGE',
ltc: 'LTC'
};

const data = _.cloneDeep(notification.data);
Expand Down
4 changes: 2 additions & 2 deletions packages/bitcore-wallet-service/src/lib/fiatrateservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class FiatRateService {

_fetch(cb?) {
cb = cb || function() {};
const coins = ['btc', 'bch', 'eth', 'xrp', 'doge'];
const coins = ['btc', 'bch', 'eth', 'xrp', 'doge', 'ltc'];
const provider = this.providers[0];

// async.each(this.providers, (provider, next) => {
Expand Down Expand Up @@ -253,7 +253,7 @@ export class FiatRateService {
// Oldest date in timestamp range in epoch number ex. 24 hours ago
const now = Date.now() - Defaults.FIAT_RATE_FETCH_INTERVAL * 60 * 1000;
const ts = _.isNumber(opts.ts) ? opts.ts : now;
const coins = ['btc', 'bch', 'eth', 'xrp', 'doge'];
const coins = ['btc', 'bch', 'eth', 'xrp', 'doge', 'ltc'];

async.map(
coins,
Expand Down
3 changes: 2 additions & 1 deletion packages/bitcore-wallet-service/src/lib/model/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export class Address {
static Bitcore = {
btc: require('bitcore-lib'),
bch: require('bitcore-lib-cash'),
doge: require('bitcore-lib-doge')
doge: require('bitcore-lib-doge'),
ltc: require('bitcore-lib-ltc')
};

static create(opts) {
Expand Down
3 changes: 2 additions & 1 deletion packages/bitcore-wallet-service/src/lib/model/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const Bitcore = {
bch: require('bitcore-lib-cash'),
eth: require('bitcore-lib'),
xrp: require('bitcore-lib'),
doge: require('bitcore-lib-doge')
doge: require('bitcore-lib-doge'),
ltc: require('bitcore-lib-ltc')
};

export interface IWallet {
Expand Down
Loading

0 comments on commit 17fdf7a

Please sign in to comment.