mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
update to contracts 0.5.3
This commit is contained in:
parent
9a228c131b
commit
b78a57c59a
6
package-lock.json
generated
6
package-lock.json
generated
@ -939,9 +939,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@oceanprotocol/contracts": {
|
"@oceanprotocol/contracts": {
|
||||||
"version": "0.5.1",
|
"version": "0.5.3",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.5.3.tgz",
|
||||||
"integrity": "sha512-bt5uwh79D759H6O4bAv+ycGdZQISFAxi65cqIygzA9hwsu29+GuOLwu1mxrzl2lVNLs6Emxo7TaDv0jAoyqnCg=="
|
"integrity": "sha512-gJ8qQACJgxOPIrPE0OFQ09iYXBAisOGg56EmelQlsMUgp0yY0DKgBntDP83S/Ho1yBjGygqfxCjQrPH63hh/PA=="
|
||||||
},
|
},
|
||||||
"@octokit/auth-token": {
|
"@octokit/auth-token": {
|
||||||
"version": "2.4.2",
|
"version": "2.4.2",
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ethereum-navigator/navigator": "^0.5.0",
|
"@ethereum-navigator/navigator": "^0.5.0",
|
||||||
"@oceanprotocol/contracts": "^0.5.1",
|
"@oceanprotocol/contracts": "^0.5.3",
|
||||||
"decimal.js": "^10.2.0",
|
"decimal.js": "^10.2.0",
|
||||||
"fs": "0.0.1-security",
|
"fs": "0.0.1-security",
|
||||||
"lzma": "^2.3.2",
|
"lzma": "^2.3.2",
|
||||||
|
@ -343,6 +343,7 @@ export class DataTokens {
|
|||||||
|
|
||||||
/** Start Order
|
/** Start Order
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
|
* @param {String} consumer consumer Address
|
||||||
* @param {String} amount
|
* @param {String} amount
|
||||||
* @param {Number} serviceId
|
* @param {Number} serviceId
|
||||||
* @param {String} mpFeeAddress
|
* @param {String} mpFeeAddress
|
||||||
@ -351,6 +352,7 @@ export class DataTokens {
|
|||||||
*/
|
*/
|
||||||
public async startOrder(
|
public async startOrder(
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
|
consumer: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
serviceId: number,
|
serviceId: number,
|
||||||
mpFeeAddress: string,
|
mpFeeAddress: string,
|
||||||
@ -362,7 +364,12 @@ export class DataTokens {
|
|||||||
if (!mpFeeAddress) mpFeeAddress = '0x0000000000000000000000000000000000000000'
|
if (!mpFeeAddress) mpFeeAddress = '0x0000000000000000000000000000000000000000'
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await datatoken.methods
|
const trxReceipt = await datatoken.methods
|
||||||
.startOrder(this.web3.utils.toWei(amount), String(serviceId), mpFeeAddress)
|
.startOrder(
|
||||||
|
consumer,
|
||||||
|
this.web3.utils.toWei(amount),
|
||||||
|
String(serviceId),
|
||||||
|
mpFeeAddress
|
||||||
|
)
|
||||||
.send({ from: address, gas: 600000 })
|
.send({ from: address, gas: 600000 })
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -38,6 +38,8 @@ export interface Order {
|
|||||||
amount: string
|
amount: string
|
||||||
timestamp: number
|
timestamp: number
|
||||||
transactionHash: string
|
transactionHash: string
|
||||||
|
consumer: string
|
||||||
|
payer: string
|
||||||
did?: string
|
did?: string
|
||||||
serviceId?: number
|
serviceId?: number
|
||||||
serviceType?: string
|
serviceType?: string
|
||||||
@ -462,19 +464,22 @@ export class Assets extends Instantiable {
|
|||||||
* Orders & pays for a service
|
* Orders & pays for a service
|
||||||
* @param {String} did
|
* @param {String} did
|
||||||
* @param {String} serviceType
|
* @param {String} serviceType
|
||||||
* @param {String} consumerAddress
|
* @param {String} payerAddress
|
||||||
* @param {Number} serviceIndex
|
* @param {Number} serviceIndex
|
||||||
* @param {String} mpAddress mp fee collector address
|
* @param {String} mpAddress mp fee collector address
|
||||||
|
* @param {String} consumerAddress Optionally, if the consumer is another address than payer
|
||||||
* @return {Promise<String>} transactionHash of the payment
|
* @return {Promise<String>} transactionHash of the payment
|
||||||
*/
|
*/
|
||||||
public async order(
|
public async order(
|
||||||
did: string,
|
did: string,
|
||||||
serviceType: string,
|
serviceType: string,
|
||||||
consumerAddress: string,
|
payerAddress: string,
|
||||||
serviceIndex = -1,
|
serviceIndex = -1,
|
||||||
mpAddress?: string
|
mpAddress?: string,
|
||||||
|
consumerAddress?: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
let service
|
let service
|
||||||
|
if (!consumerAddress) consumerAddress = payerAddress
|
||||||
if (serviceIndex === -1) {
|
if (serviceIndex === -1) {
|
||||||
service = await this.getServiceByType(did, serviceType)
|
service = await this.getServiceByType(did, serviceType)
|
||||||
serviceIndex = service.index
|
serviceIndex = service.index
|
||||||
@ -487,7 +492,7 @@ export class Assets extends Instantiable {
|
|||||||
const providerData = await this.initialize(
|
const providerData = await this.initialize(
|
||||||
did,
|
did,
|
||||||
serviceType,
|
serviceType,
|
||||||
consumerAddress,
|
payerAddress,
|
||||||
serviceIndex,
|
serviceIndex,
|
||||||
service.serviceEndpoint
|
service.serviceEndpoint
|
||||||
)
|
)
|
||||||
@ -502,7 +507,7 @@ export class Assets extends Instantiable {
|
|||||||
)
|
)
|
||||||
if (previousOrder) return previousOrder
|
if (previousOrder) return previousOrder
|
||||||
const balance = new BigNumber(
|
const balance = new BigNumber(
|
||||||
await datatokens.balance(providerData.dataToken, consumerAddress)
|
await datatokens.balance(providerData.dataToken, payerAddress)
|
||||||
)
|
)
|
||||||
const totalCost = new BigNumber(String(providerData.numTokens))
|
const totalCost = new BigNumber(String(providerData.numTokens))
|
||||||
if (balance.isLessThan(totalCost)) {
|
if (balance.isLessThan(totalCost)) {
|
||||||
@ -516,10 +521,11 @@ export class Assets extends Instantiable {
|
|||||||
}
|
}
|
||||||
const txid = await datatokens.startOrder(
|
const txid = await datatokens.startOrder(
|
||||||
providerData.dataToken,
|
providerData.dataToken,
|
||||||
|
consumerAddress,
|
||||||
String(providerData.numTokens),
|
String(providerData.numTokens),
|
||||||
serviceIndex,
|
serviceIndex,
|
||||||
mpAddress,
|
mpAddress,
|
||||||
consumerAddress
|
payerAddress
|
||||||
)
|
)
|
||||||
if (txid) return txid.transactionHash
|
if (txid) return txid.transactionHash
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -605,26 +611,32 @@ export class Assets extends Instantiable {
|
|||||||
fromBlock?: number
|
fromBlock?: number
|
||||||
): Promise<Order[]> {
|
): Promise<Order[]> {
|
||||||
const results: Order[] = []
|
const results: Order[] = []
|
||||||
const address = this.web3.utils.toChecksumAddress(account.getId())
|
const address = account.getId().toLowerCase()
|
||||||
const events = await this.web3.eth.getPastLogs({
|
const events = await this.web3.eth.getPastLogs({
|
||||||
topics: [
|
topics: [
|
||||||
['0x24c95b9bea47f62df4b9eea32c98c597eccfc5cac47f8477647be875ad925eee', address]
|
[
|
||||||
|
'0xe1c4fa794edfa8f619b8257a077398950357b9c6398528f94480307352f9afcc',
|
||||||
|
null,
|
||||||
|
'0x000000000000000000000000' + address.substring(address.length - 40)
|
||||||
|
]
|
||||||
],
|
],
|
||||||
fromBlock: fromBlock || 0
|
fromBlock: fromBlock || 0
|
||||||
})
|
})
|
||||||
for (let i = 0; i < events.length; i++) {
|
for (let i = 0; i < events.length; i++) {
|
||||||
const blockDetails = await this.web3.eth.getBlock(events[i].blockNumber)
|
|
||||||
const order: Order = {
|
const order: Order = {
|
||||||
dtAddress: events[i].address,
|
dtAddress: events[i].address,
|
||||||
timestamp: parseInt(String(blockDetails.timestamp)),
|
timestamp: 0,
|
||||||
transactionHash: events[i].transactionHash,
|
transactionHash: events[i].transactionHash,
|
||||||
amount: null
|
amount: null,
|
||||||
|
consumer: '0x' + events[i].topics[1].substring(events[i].topics[1].length - 40),
|
||||||
|
payer: '0x' + events[i].topics[2].substring(events[i].topics[2].length - 40)
|
||||||
}
|
}
|
||||||
const params = this.web3.eth.abi.decodeParameters(
|
const params = this.web3.eth.abi.decodeParameters(
|
||||||
['uint256', 'uint256', 'uint256', 'uint256'],
|
['uint256', 'uint256', 'uint256', 'uint256'],
|
||||||
events[i].data
|
events[i].data
|
||||||
)
|
)
|
||||||
order.serviceId = parseInt(params[1])
|
order.serviceId = parseInt(params[1])
|
||||||
|
order.timestamp = parseInt(params[2])
|
||||||
order.amount = this.web3.utils.fromWei(params[0])
|
order.amount = this.web3.utils.fromWei(params[0])
|
||||||
order.did = didPrefixed(didNoZeroX(order.dtAddress))
|
order.did = didPrefixed(didNoZeroX(order.dtAddress))
|
||||||
const service = await this.getServiceByIndex(order.did, order.serviceId)
|
const service = await this.getServiceByIndex(order.did, order.serviceId)
|
||||||
|
@ -44,13 +44,13 @@ const configs: ConfigHelperConfig[] = [
|
|||||||
networkId: 4,
|
networkId: 4,
|
||||||
network: 'rinkeby',
|
network: 'rinkeby',
|
||||||
nodeUri: 'https://rinkeby.infura.io/v3',
|
nodeUri: 'https://rinkeby.infura.io/v3',
|
||||||
factoryAddress: '0x241D0f315d2bfe32b90282e6863AC22A309EbFa0',
|
factoryAddress: '0x3fd7A00106038Fb5c802c6d63fa7147Fe429E83a',
|
||||||
oceanTokenAddress: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07',
|
oceanTokenAddress: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07',
|
||||||
metadataStoreUri: 'https://aquarius.rinkeby.v3.dev-ocean.com',
|
metadataStoreUri: 'https://aquarius.rinkeby.v3.dev-ocean.com',
|
||||||
providerUri: 'https://provider.rinkeby.v3.dev-ocean.com',
|
providerUri: 'https://provider.rinkeby.v3.dev-ocean.com',
|
||||||
poolFactoryAddress: '0xf32E0784F5D127471883aF938c50349A97aF7085',
|
poolFactoryAddress: '0x53eDF9289B0898e1652Ce009AACf8D25fA9A42F8',
|
||||||
fixedRateExchangeAddress: '0x223B65841d5BAE99c615D0Da7980b2Fc0aFF1dB2',
|
fixedRateExchangeAddress: '0xeD1DfC5F3a589CfC4E8B91C1fbfC18FC6699Fbde',
|
||||||
metadataContractAddress: '0x0220D0b4FfCC4A14C7601215aA23da06d5b1c921'
|
metadataContractAddress: '0x2C63bf697f74C72CFB727Fb5eB8e6266cE341e13'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
networkId: 1,
|
networkId: 1,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user