You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the adapter in place, the CP_Account API endpoint must be updated to use it while maintaining existing functionality. Functions should be updated in place whenever possible -- that is, names and existing parameters should not change.
Functional Branching
To enable branching based on cryptocurrency, if not already supported, additional parameters may be added that should default to existing functionality.
For example, if the following function needs to be updated to support Monero and other cryptocurrencies:
... an additional parameter should be added that will default to the current functionality if not supplied:
function makeHDWallet(privKey, currencyType="bitcoin") {
if (currencyType == "bitcoin") {
try {
if (privKey.indexOf("xprv") == 0) {
//mainnet
var wallet = bitcoin.bip32.fromBase58(privKey);
} else {
//testnett
wallet = bitcoin.bip32.fromBase58(privKey, bitcoin.networks.testnet);
}
} catch (err) {
console.error(err.stack);
return (null);
}
if (wallet == undefined) {
return (null);
}
return (wallet);
} else if (currencyType == "monero") {
//make a Monero HD wallet
}
}
Since any existing calls are providing only one parameter and the new, second parameter defaults to "bitcoin", any current functionality will continue to work while any new functionality can incorporate the new parameter.
That being said, anywhere that makeHDWallet is called will probably still need to be updated since the HD wallet for the new cryptocurrency will need to be generated somewhere.
Luckily, on the server side there are only two API endpoints that include cryptocurrency transactions; primarily CP_Account, and sometimes CP_SmartContract.
Additionally, startup and configuration information for the newly-added cryptocurrency will need to be processed at server startup:
adjustEnvironment();//adjust for local runtime environment
if(postLoadConfig()==true){
//account system successfully created immediately
}else{
//account system not yet successfully created
}
}).catch(err=>{
console.error("Couldn't load or parse configuration data.");
console.error(err);
})
As with the adapter, it's best to keep any newly-added functionality in modular form. That is, as async (where required) functions that are passed references rather than relying on static locations of objects such as the main configuration.
Function Updates
The functions that can be may need to be updated or re-created include:
Obviously some of these functions are fairly specific to Bitcoin so the creation of new functions in their place may be good idea.
When it comes to generic functions such as cashOutToAddress or sendTransaction, however, functional branching (if..else, switch..case, etc.), within the functions makes sense since they can be applied more broadly than just for a single cryptocurrency (e.g. Bitcoin). If in doubt, branch within the function rather than creating a new one.
Additional information, including code documentation and formatting, can be found here: #48
The text was updated successfully, but these errors were encountered:
monicanagent
changed the title
Update CP_Account API endpoint to support Monero / multiple cryptocurrencies
Update Services API endpoints to support Monero / multiple cryptocurrencies
Mar 21, 2019
This task is preceded by #53
Overview
With the adapter in place, the
CP_Account
API endpoint must be updated to use it while maintaining existing functionality. Functions should be updated in place whenever possible -- that is, names and existing parameters should not change.Functional Branching
To enable branching based on cryptocurrency, if not already supported, additional parameters may be added that should default to existing functionality.
For example, if the following function needs to be updated to support Monero and other cryptocurrencies:
cypherpoker.js/src/server/api/CP_Account.js
Lines 487 to 503 in 1a4e605
... an additional parameter should be added that will default to the current functionality if not supplied:
Since any existing calls are providing only one parameter and the new, second parameter defaults to "bitcoin", any current functionality will continue to work while any new functionality can incorporate the new parameter.
That being said, anywhere that
makeHDWallet
is called will probably still need to be updated since the HD wallet for the new cryptocurrency will need to be generated somewhere.Luckily, on the server side there are only two API endpoints that include cryptocurrency transactions; primarily CP_Account, and sometimes CP_SmartContract.
Additionally, startup and configuration information for the newly-added cryptocurrency will need to be processed at server startup:
cypherpoker.js/src/server/server.js
Lines 892 to 1144 in 1a4e605
As with the adapter, it's best to keep any newly-added functionality in modular form. That is, as
async
(where required) functions that are passed references rather than relying on static locations of objects such as the main configuration.Function Updates
The functions that can be may need to be updated or re-created include:
cypherpoker.js/src/server/api/CP_Account.js
Line 487 in 1a4e605
cypherpoker.js/src/server/api/CP_Account.js
Line 535 in 1a4e605
cypherpoker.js/src/server/api/CP_Account.js
Line 558 in 1a4e605
cypherpoker.js/src/server/api/CP_Account.js
Line 833 in 1a4e605
cypherpoker.js/src/server/api/CP_Account.js
Line 870 in 1a4e605
cypherpoker.js/src/server/api/CP_Account.js
Line 912 in 1a4e605
cypherpoker.js/src/server/api/CP_Account.js
Line 964 in 1a4e605
cypherpoker.js/src/server/api/CP_Account.js
Line 1019 in 1a4e605
cypherpoker.js/src/server/api/CP_Account.js
Line 1052 in 1a4e605
cypherpoker.js/src/server/api/CP_Account.js
Line 1070 in 1a4e605
cypherpoker.js/src/server/api/CP_Account.js
Line 1224 in 1a4e605
cypherpoker.js/src/server/api/CP_Account.js
Line 1260 in 1a4e605
Obviously some of these functions are fairly specific to Bitcoin so the creation of new functions in their place may be good idea.
When it comes to generic functions such as
cashOutToAddress
orsendTransaction
, however, functional branching (if..else
,switch..case
, etc.), within the functions makes sense since they can be applied more broadly than just for a single cryptocurrency (e.g. Bitcoin). If in doubt, branch within the function rather than creating a new one.Additional information, including code documentation and formatting, can be found here: #48
The text was updated successfully, but these errors were encountered: