Skip to content

Commit

Permalink
Merge branch 'dev-alessandro'
Browse files Browse the repository at this point in the history
  • Loading branch information
allemanfredi committed Apr 29, 2021
2 parents f49fbec + 7a915a8 commit a734430
Show file tree
Hide file tree
Showing 70 changed files with 2,009 additions and 292 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ module.exports = {
'no-mixed-requires': 2,
'no-new-require': 0,
'no-path-concat': 1,
'no-sync': 1
'no-sync': 1,
'no-mixed-operators': 1
// stylistic (leaving up to standard)

// ECMAScript 6 (tbd)
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "0.10.0"
"version": "0.11.0"
}
8 changes: 4 additions & 4 deletions packages/ptokens-deposit-address/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ptokens-deposit-address",
"version": "0.10.0",
"version": "0.11.0",
"description": "repo holding the code related to deposit addresses",
"repository": "https://github.com/provable-things/ptokens.js/tree/master/packages/ptokens-deposit-address",
"main": "dist/ptokens-deposit-address.cjs.js",
Expand Down Expand Up @@ -32,9 +32,9 @@
"bitcoinjs-lib": "^5.1.6",
"chai": "^4.2.0",
"eosjs": "^20.0.3",
"ptokens-node": "^0.10.0",
"ptokens-providers": "^0.10.0",
"ptokens-utils": "^0.10.0",
"ptokens-node": "^0.11.0",
"ptokens-providers": "^0.11.0",
"ptokens-utils": "^0.11.0",
"web3": "^1.2.2"
},
"devDependencies": {
Expand Down
45 changes: 28 additions & 17 deletions packages/ptokens-deposit-address/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Web3PromiEvent from 'web3-core-promievent'
import Web3Utils from 'web3-utils'
import BigNumber from 'bignumber.js'
import * as bitcoin from 'bitcoinjs-lib'
import * as utils from 'ptokens-utils'
Expand All @@ -10,7 +9,8 @@ const POLLING_TIME = 3000
const confirmations = {
btc: 1,
ltc: 4,
doge: 1
doge: 1,
rvn: 25
}

// NOTE: will be removed in versions >= 1.0.0
Expand Down Expand Up @@ -44,7 +44,7 @@ bitcoin.networks.litecoinTestnet = {
}

bitcoin.networks.dogecoin = {
messagePrefix: '\x19Dogecoin Signed Message:\n',
messagePrefix: '\x1aRavencoin Signed Message:\n',
bip32: {
public: 0x02facafd,
private: 0x02fac398
Expand All @@ -54,10 +54,21 @@ bitcoin.networks.dogecoin = {
wif: 0x9e
}

bitcoin.networks.ravencoin = {
messagePrefix: '\x1aRavencoin Signed Message:\n',
bip32: {
public: 0x0488b21e,
private: 0x0488ade4
},
pubKeyHash: 0x3c,
scriptHash: 0x7a,
wif: 0x80
}

const {
constants: {
networks: { BitcoinMainnet, BitcoinTestnet, LitecoinMainnet, LitecoinTestnet, DogecoinMainnet },
blockchains: { Bitcoin, Litecoin, Dogecoin }
networks: { BitcoinMainnet, BitcoinTestnet, LitecoinMainnet, LitecoinTestnet, DogecoinMainnet, RavencoinMainnet },
blockchains: { Bitcoin, Litecoin, Dogecoin, Ravencoin }
}
} = utils
const NETWORKS = {
Expand All @@ -71,6 +82,9 @@ const NETWORKS = {
},
[Dogecoin]: {
[DogecoinMainnet]: bitcoin.networks.dogecoin
},
[Ravencoin]: {
[RavencoinMainnet]: bitcoin.networks.ravencoin
}
}

Expand All @@ -93,12 +107,6 @@ export class DepositAddress {
* @param {String} _hostAddress
*/
async generate(_hostAddress) {
if (this.hostBlockchain === utils.constants.blockchains.Ethereum && !Web3Utils.isAddress(_hostAddress))
throw new Error('Invalid Ethereum Address')

if (this.hostBlockchain === utils.constants.blockchains.Eosio && !utils.eos.isValidAccountName(_hostAddress))
throw new Error('Invalid EOS Account')

try {
const { nonce, enclavePublicKey, nativeDepositAddress } = await this.node.getNativeDepositAddress(_hostAddress)

Expand All @@ -122,6 +130,7 @@ export class DepositAddress {
blockchains: { Eosio, Telos }
}
} = utils

const network = NETWORKS[this.nativeBlockchain][this.nativeNetwork]
if (!network) throw new Error('Please use a valid combination of nativeNetwork and nativeBlockchain')

Expand Down Expand Up @@ -152,12 +161,12 @@ export class DepositAddress {
waitForDeposit() {
const promiEvent = Web3PromiEvent()

if (!this.hostApi) {
promiEvent.reject('Provider not specified. Impossible to monitor the tx')
return
}

const start = async () => {
if (!this.hostApi) {
promiEvent.reject('Provider not specified. Impossible to monitor the tx')
return
}

if (!this.value) promiEvent.reject('Please generate a deposit address')

const shortNativeBlockchain = utils.helpers.getBlockchainShortType(this.nativeBlockchain)
Expand All @@ -174,7 +183,9 @@ export class DepositAddress {
)

const broadcastedHostTxReport = await this.node.monitorIncomingTransaction(nativeTxId, promiEvent.eventEmitter)
const hostTxReceipt = await utils[shortHostBlockchain].waitForTransactionConfirmation(
const hostTxReceipt = await utils[
shortHostBlockchain === 'bsc' ? 'eth' : shortHostBlockchain
].waitForTransactionConfirmation(
this.hostApi,
broadcastedHostTxReport.broadcast_tx_hash,
HOST_NODE_POLLING_TIME_INTERVAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const PLTC_ON_ETH_MAINNET = 'https://pltconeth-node-1a.ngrok.io'
const PBTC_ON_ETH_ROPSTEN = 'https://nuc-bridge-3.ngrok.io/'
const PLTC_ON_ETH_ROPSTEN = 'https://nuc-bridge-2.ngrok.io'
const PDOGE_ON_ETH_MAINNET = 'http://51.195.136.212:3002'
const PRVN_ON_ETH_MAINNET = 'https://prvnonbsc-node-1a.ngrok.io'

const INFURA_MAINNET = 'https://mainnet.infura.io/v3/4762c881ac0c4938be76386339358ed6'
const INFURA_ROPSTEN = 'https://ropsten.infura.io/v3/4762c881ac0c4938be76386339358ed6'
Expand Down Expand Up @@ -223,3 +224,20 @@ test('Should generate correctly a pDOGE deposit address on Ethereum Mainnet', as
await depositAddress.generate(ETH_TESTING_ADDRESS)
expect(depositAddress.verify()).to.be.eq(true)
})

test('Should generate correctly a pRVN deposit address on Binance Smart Chain Mainnet', async () => {
const node = new Node({
pToken: constants.pTokens.pRVN,
blockchain: constants.blockchains.BinanceSmartChain,
provider: new HttpProvider(PRVN_ON_ETH_MAINNET)
})
const depositAddress = new DepositAddress({
nativeBlockchain: constants.blockchains.Ravencoin,
nativeNetwork: constants.networks.RavencoinMainnet,
hostBlockchain: constants.blockchains.BinanceSmartChain,
hostNetwork: constants.networks.BinanceSmartChainMainnet,
node
})
await depositAddress.generate(ETH_TESTING_ADDRESS)
expect(depositAddress.verify()).to.be.eq(true)
})
8 changes: 4 additions & 4 deletions packages/ptokens-node-selector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ptokens-node-selector",
"version": "0.10.0",
"version": "0.11.0",
"description": "repo holding the code for selecting validator nodes",
"repository": "https://github.com/provable-things/ptokens.js/tree/master/packages/ptokens-node-selector",
"main": "dist/ptokens-node-selector.cjs.js",
Expand All @@ -20,9 +20,9 @@
"@babel/runtime": "^7.3.1",
"@types/node": "^12.6.1",
"chai": "^4.2.0",
"ptokens-node": "^0.10.0",
"ptokens-providers": "^0.10.0",
"ptokens-utils": "^0.10.0"
"ptokens-node": "^0.11.0",
"ptokens-providers": "^0.11.0",
"ptokens-utils": "^0.11.0"
},
"devDependencies": {
"dtslint": "0.4.2",
Expand Down
Loading

0 comments on commit a734430

Please sign in to comment.