Skip to content

Commit

Permalink
Release/6.1.0 (#121)
Browse files Browse the repository at this point in the history
* Added custom BlockchainError and decorator in order to handle updated contracts in the Hub

* Add blockchain constants

* Remove shortening of blockchain name

* Add chainId to blockchain constants

* Add set right blockchain name if old are used

* Add constants intstead of strings

* Added function to validate options for the 'isValidUAL' function

* Added additional info to the errors in the 'isValidUAL' function

* Add case insensitive comparison for contract address

* Add hardhat2 constants

* Fix missing comma

* Add chain it to chiado and gnosis

* Rename chiado to gnosis

* Bumped version to 6.1.0

* Validate blockchain name withou network name

* Added 'environment' to options, splitted blockchains by environment, remove redundant code, added logic to update contracts when executing contract functions

* Fixes for new UALs

* Remove decorator

* Fix add await when calling updateContractInstances

* Fix use correct error reference

* Update dkg-evm-module version

* Add fethingc gas price from gnosis oracle

* Add logic for using gas price oracle to getNetworkGasPrice method

* Add missing await

* Return gas value

* Fix using correct blockchain name

* Fix return gasPrice in getNetworkGasPrice

* Use gasPriceOracleLink from constants

* Fix priceOracleLink

* Fix getting gas for gnosis mainnet

* Add webpack build

* Fix error using reference from try block in catch

* Remove BlockchainError

* Add Gnsosi Hub contract

* Remove gnosi:100 from blockchain constans

* Remove handleContractUpdates

* Update build

* Update otp::alphanet constant name

---------

Co-authored-by: Mihajlo Pavlovic <[email protected]>
  • Loading branch information
u-hubar and Mihajlo-Pavlovic authored Dec 21, 2023
1 parent 7122540 commit 5f09a73
Show file tree
Hide file tree
Showing 19 changed files with 711 additions and 387 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
node: true,
},
extends: ['airbnb/base', 'prettier'],
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module',
ecmaVersion: 'latest',
Expand Down
75 changes: 51 additions & 24 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,60 @@ const PRIVATE_ASSERTION_PREDICATE = 'https://ontology.origintrail.io/dkg/1.0#pri
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

const BLOCKCHAINS = {
ganache: {
rpc: 'http://localhost:7545',
hubContract: '0x209679fA3B658Cd0fC74473aF28243bfe78a9b12',
development: {
'hardhat1:31337': {
rpc: 'http://localhost:8545',
hubContract: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
},
'hardhat2:31337': {
rpc: 'http://localhost:9545',
hubContract: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
},
'otp::2043': {
rpc: 'http://parachain-alphanet-02.origin-trail.network:9933',
hubContract: '0x7585a99C5C150a08f5CDeFD16465C6De8D41EbbD',
},
},
hardhat: {
rpc: 'http://localhost:8545',
hubContract: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
devnet: {
'otp:2160': {
rpc: 'https://lofar-tm-rpc.origin-trail.network',
hubContract: '0x833048F6e6BEa78E0AAdedeCd2Dc2231dda443FB',
},
'gnosis:10200': {
rpc: 'https://rpc.chiadochain.net',
hubContract: '0xD2bA102A0b11944d00180eE8136208ccF87bC39A',
gasPriceOracleLink: 'https://blockscout.chiadochain.net/api/v1/gas-price-oracle',
},
},
polygon: {
rpc: 'https://matic-mumbai.chainstacklabs.com',
hubContract: '0xdaa16AC171CfE8Df6F79C06E7EEAb2249E2C9Ec8', // TODO: change to Asset Contract
testnet: {
'otp:20430': {
rpc: 'https://lofar-testnet.origin-trail.network',
hubContract: '0xBbfF7Ea6b2Addc1f38A0798329e12C08f03750A6',
},
'gnosis:10200': {
rpc: 'https://rpc.chiadochain.net',
hubContract: '0xC06210312C9217A0EdF67453618F5eB96668679A',
gasPriceOracleLink: 'https://blockscout.chiadochain.net/api/v1/gas-price-oracle',
},
},
'otp::alphanet': {
rpc: 'http://parachain-alphanet-02.origin-trail.network:9933',
hubContract: '0x7585a99C5C150a08f5CDeFD16465C6De8D41EbbD',
},
'otp::devnet': {
rpc: 'https://lofar-tm-rpc.origin-trail.network',
hubContract: '0x833048F6e6BEa78E0AAdedeCd2Dc2231dda443FB',
},
'otp::testnet': {
rpc: 'https://lofar-testnet.origin-trail.network',
hubContract: '0xBbfF7Ea6b2Addc1f38A0798329e12C08f03750A6',
},
'otp::mainnet': {
rpc: 'https://astrosat-parachain-rpc.origin-trail.network',
hubContract: '0x5fA7916c48Fe6D5F1738d12Ad234b78c90B4cAdA',
mainnet: {
'otp:2043': {
rpc: 'https://astrosat-parachain-rpc.origin-trail.network',
hubContract: '0x5fA7916c48Fe6D5F1738d12Ad234b78c90B4cAdA',
},
},
};

const BLOCKCHAINS_RENAME_PAIRS = {
hardhat1: 'hardhat1:31337',
hardhat2: 'hardhat2:31337',
'otp::devnet': 'otp:2160',
'otp::testnet': 'otp:20430',
'otp::mainnet': 'otp:2043',
};

const MAX_BLOCKCHAIN_CALL_RETRIES = 3;

const TRANSACTION_RETRY_ERRORS = [
'transaction was not mined',
'already known',
Expand Down Expand Up @@ -134,6 +158,7 @@ const OPERATIONS_STEP_STATUS = {
const DEFAULT_GET_LOCAL_STORE_RESULT_FREQUENCY = 0.5;

const DEFAULT_PARAMETERS = {
ENVIRONMENT: 'mainnet',
PORT: 8900,
FREQUENCY: 5,
MAX_NUMBER_OF_RETRIES: 5,
Expand All @@ -155,6 +180,8 @@ module.exports = {
PRIVATE_ASSERTION_PREDICATE,
ZERO_ADDRESS,
BLOCKCHAINS,
BLOCKCHAINS_RENAME_PAIRS,
MAX_BLOCKCHAIN_CALL_RETRIES,
TRANSACTION_RETRY_ERRORS,
WEBSOCKET_PROVIDER_OPTIONS,
OPERATIONS,
Expand Down
2 changes: 1 addition & 1 deletion dist/dkg.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/demo-private.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const DKG = require('../index.js');

const ENVIRONMENT = 'development';
const OT_NODE_HOSTNAME = 'http://localhost';
const OT_NODE_PORT = '8900';
const PUBLIC_KEY = '0xBaF76aC0d0ef9a2FFF76884d54C9D3e270290a43';
const PRIVATE_KEY = '0x9b9af041edc816692276ac3c8f1d5565e3c01ddff80ec982943a29bd8d1d8863';

const DkgClient = new DKG({
environment: ENVIRONMENT,
endpoint: OT_NODE_HOSTNAME,
port: OT_NODE_PORT,
blockchain: {
Expand Down
1 change: 1 addition & 0 deletions examples/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ <h3>Asset data</h3>
initializeDKGClient(blockchain) {
console.log(this.selectedNetwork)
window.DkgClient = new DKG({
environment: 'development',
endpoint: 'http://localhost',
blockchain: {
name: this.selectedNetwork,
Expand Down
4 changes: 3 additions & 1 deletion examples/demo.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const jsonld = require('jsonld');
const DKG = require('../index.js');

const ENVIRONMENT = 'development';
const OT_NODE_HOSTNAME = 'http://localhost';
const OT_NODE_PORT = '8900';
const PUBLIC_KEY = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
const PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';

const DkgClient = new DKG({
environment: ENVIRONMENT,
endpoint: OT_NODE_HOSTNAME,
port: OT_NODE_PORT,
blockchain: {
name: 'hardhat',
name: 'hardhat1',
publicKey: PUBLIC_KEY,
privateKey: PRIVATE_KEY,
},
Expand Down
28 changes: 13 additions & 15 deletions managers/asset-operations-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ class AssetOperationsManager {
throw new Error(`Invalid DKG prefix. Expected: 'dkg'. Received: '${prefixes[1]}'.`);
}

if (prefixes[2] !== blockchain.name) {
if (prefixes[2] !== blockchain.name.split(':')[0]) {
throw new Error(
`Invalid blockchain name in the UAL prefix. Expected: '${blockchain.name}'. Received: '${prefixes[2]}'.`,
`Invalid blockchain name in the UAL prefix. Expected: '${
blockchain.name.split(':')[0]
}'. Received: '${prefixes[2]}'.`,
);
}

Expand All @@ -93,7 +95,7 @@ class AssetOperationsManager {

try {
const owner = await this.blockchainService.getAssetOwner(parts[2], blockchain);
if (owner === ZERO_ADDRESS) {
if (!owner || owner === ZERO_ADDRESS) {
throw new Error('Token does not exist or has no owner.');
}
return true;
Expand Down Expand Up @@ -320,7 +322,7 @@ class AssetOperationsManager {
endpoint,
port,
authToken,
blockchain.name.startsWith('otp') ? 'otp' : blockchain.name,
blockchain.name,
epochsNum,
publicAssertionSizeInBytes,
contentAssetStorageAddress,
Expand All @@ -344,7 +346,7 @@ class AssetOperationsManager {
);

const resolvedUAL = {
blockchain: blockchain.name.startsWith('otp') ? 'otp' : blockchain.name,
blockchain: blockchain.name,
contract: contentAssetStorageAddress,
tokenId,
};
Expand Down Expand Up @@ -380,11 +382,7 @@ class AssetOperationsManager {
operationId,
);

const UAL = deriveUAL(
blockchain.name.startsWith('otp') ? 'otp' : blockchain.name,
contentAssetStorageAddress,
tokenId,
);
const UAL = deriveUAL(blockchain.name, contentAssetStorageAddress, tokenId);

if (operationResult.status === OPERATION_STATUSES.FAILED) {
return {
Expand All @@ -400,7 +398,7 @@ class AssetOperationsManager {
authToken,
publicAssertionId,
publicAssertion,
blockchain.name.startsWith('otp') ? 'otp' : blockchain.name,
blockchain.name,
contentAssetStorageAddress,
tokenId,
hashFunctionId,
Expand Down Expand Up @@ -799,7 +797,7 @@ class AssetOperationsManager {
);

const resolvedUAL = {
blockchain: blockchain.name.startsWith('otp') ? 'otp' : blockchain.name,
blockchain: blockchain.name,
contract: contentAssetStorageAddress,
tokenId,
};
Expand Down Expand Up @@ -853,7 +851,7 @@ class AssetOperationsManager {
authToken,
publicAssertionId,
publicAssertion,
blockchain.name.startsWith('otp') ? 'otp' : blockchain.name,
blockchain.name,
contentAssetStorageAddress,
tokenId,
hashFunctionId,
Expand Down Expand Up @@ -1154,7 +1152,7 @@ class AssetOperationsManager {
endpoint,
port,
authToken,
blockchain.name.startsWith('otp') ? 'otp' : blockchain.name,
blockchain.name,
epochsNumber,
latestFinalizedStateSize,
contract,
Expand Down Expand Up @@ -1335,7 +1333,7 @@ class AssetOperationsManager {
endpoint,
port,
authToken,
blockchain.name.startsWith('otp') ? 'otp' : blockchain.name,
blockchain.name,
epochsLeft,
size,
contract,
Expand Down
4 changes: 1 addition & 3 deletions managers/blockchain-operations-manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

class BlockchainOperationsManager {

constructor(services) {
this.blockchainService = services.blockchainService;
this.inputService = services.inputService;
Expand All @@ -24,7 +22,7 @@ class BlockchainOperationsManager {
*/
async getGasPrice(options = {}) {
const blockchain = this.inputService.getBlockchain(options);
return this.blockchainService.getGasPrice(blockchain);
return await this.blockchainService.getGasPrice(blockchain);
}

/**
Expand Down
17 changes: 5 additions & 12 deletions managers/network-operations-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ class NetworkOperationsManager {
* @returns {BigInt} Suggested bid for publishing Knowledge Asset with given parameters.
*/
async getBidSuggestion(publicAssertionId, sizeInBytes, options = {}) {
const {
blockchain,
endpoint,
port,
epochsNum,
hashFunctionId,
authToken,
} = this.inputService.getBidSuggestionArguments(options);
const { blockchain, endpoint, port, epochsNum, hashFunctionId, authToken } =
this.inputService.getBidSuggestionArguments(options);

const contentAssetStorageAddress = await this.blockchainService.getContractAddress(
'ContentAssetStorage',
Expand All @@ -33,15 +27,14 @@ class NetworkOperationsManager {
endpoint,
port,
authToken,
blockchain.name.startsWith('otp') ? 'otp' : blockchain.name,
blockchain.name,
epochsNum,
sizeInBytes,
contentAssetStorageAddress,
publicAssertionId,
hashFunctionId,
)
)
),
);
}

}
module.exports = NetworkOperationsManager;
Loading

0 comments on commit 5f09a73

Please sign in to comment.