Change the metadata fetching flow

This commit is contained in:
Lyubomir Kiprov 2019-07-20 12:11:13 +03:00
parent 92638c4d34
commit d188561dbc
3 changed files with 73 additions and 23 deletions

View File

@ -15,3 +15,26 @@
[2019-07-20 10:57:31]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmNUSXTixR4DZtPQ5vuBoEAZtv5Pe6CQdkgpRyPYfsbVs6] has been uploaded successfully
[2019-07-20 10:59:15]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmVv5G6UvVBAFsMQtff8Sk9p12Hn29g959wUeE3WjsdGUv] has been uploaded successfully
[2019-07-20 11:00:45]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmQiiVYUTtpg1DtiKnVKVfkfKkM7Brt7JHVFLcVf3H1yDV] has been uploaded successfully
[2019-07-20 11:04:34]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmNMPu9ykeAmmjBoN4g3zBC5HGypr6K4MFb3Tjkmd78i5B] has been uploaded successfully
[2019-07-20 11:06:41]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmScorFHZqFYze8RYNXpXuJPTh4ptwTcLeGPE5TodC6gnw] has been uploaded successfully
[2019-07-20 11:06:50]-[ERROR]-[Base-Email]: Email service verification failed due to Error: connect ECONNREFUSED 127.0.0.1:587
[2019-07-20 11:09:14]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmeyTjkdgSA2M28xugPNRXCjSmsQNHWfsNeYyCfK1FyqV9] has been uploaded successfully
[2019-07-20 11:10:55]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmQDFjSnY5pTo2k8uHgvYBFYKB1C9RtrNFxt4enLizP9Hp] has been uploaded successfully
[2019-07-20 11:12:14]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmZ4yiDhHmWf1tTsio4vrTzZrE51XKbtm8NzYUV68cxXZz] has been uploaded successfully
[2019-07-20 11:12:14]-[ERROR]-[Base-Email]: Email service verification failed due to Error: connect ECONNREFUSED 127.0.0.1:587
[2019-07-20 11:32:31]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [Qmf5RuGyCJFVVtCq7KLXgWwmgRVhTi7oKyiN1Nqk7Fw7Rv] has been uploaded successfully
[2019-07-20 11:32:31]-[ERROR]-[Base-Email]: Email service verification failed due to Error: connect ECONNREFUSED 127.0.0.1:587
[2019-07-20 11:35:27]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmcsiJkjcfuGvVYK55j9RC2DCBwvHPjrcBrG7UztM3G9xw] has been uploaded successfully
[2019-07-20 11:35:27]-[ERROR]-[Base-Email]: Email service verification failed due to Error: connect ECONNREFUSED 127.0.0.1:587
[2019-07-20 11:38:06]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmbJ1t7GmMujpvVcFpdGQ58dTxFAtNYaUxNNEXrXS9hnHJ] has been uploaded successfully
[2019-07-20 11:38:06]-[ERROR]-[Base-Email]: Email service verification failed due to Error: connect ECONNREFUSED 127.0.0.1:587
[2019-07-20 11:39:17]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmPheif9S68kEo4hzuszveWMk5LMEsUb2f5MR8nStkiZBs] has been uploaded successfully
[2019-07-20 11:39:17]-[ERROR]-[Base-Email]: Email service verification failed due to Error: connect ECONNREFUSED 127.0.0.1:587
[2019-07-20 11:45:48]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmcFPhH8yLG7ERjbEv6kyWsPEGMu2JufXud7Regdn4KNHz] has been uploaded successfully
[2019-07-20 11:45:48]-[ERROR]-[Base-Email]: Email service verification failed due to Error: connect ECONNREFUSED 127.0.0.1:587
[2019-07-20 11:47:31]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmWvNbgnR82ZkjWmAC7SMisA7k7zKCz7Fqu9HKVwyhJqFY] has been uploaded successfully
[2019-07-20 11:47:31]-[ERROR]-[Base-Email]: Email service verification failed due to Error: connect ECONNREFUSED 127.0.0.1:587
[2019-07-20 11:49:43]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmRtZmATHLNgxSZPbsDXaDiRe7hURagzCWYqbG7rdtS9T1] has been uploaded successfully
[2019-07-20 11:50:02]-[ERROR]-[Base-Email]: Email service verification failed due to Error: connect ECONNREFUSED 127.0.0.1:587
[2019-07-20 12:10:07]-[INFO]-[DApps-Metadata-Controller]: A dapp metadata with hash [QmYA7iGvK4641Fu2uPSKe5ahUmrMxrksFDtigvQb4VDtXd] has been uploaded successfully
[2019-07-20 12:10:07]-[ERROR]-[Base-Email]: Email service verification failed due to Error: connect ECONNREFUSED 127.0.0.1:587

View File

@ -9,6 +9,20 @@ import DiscoverContract from '../../../../embarkArtifacts/contracts/Discover'
const BN = require('bn.js')
const EMPTY_METADATA = {
developer: '',
id: '',
metadata: {
status: 'EMPTY',
},
balance: 0,
rate: 0,
available: 0,
votesMinted: 0,
votesCast: 0,
effectiveBalance: 0,
}
class DiscoverService extends BlockchainService {
constructor(sharedContext) {
super(sharedContext, DiscoverContract, DiscoverValidator)
@ -17,10 +31,11 @@ class DiscoverService extends BlockchainService {
// View methods
async upVoteEffect(id, amount) {
await this.validator.validateUpVoteEffect(id, amount)
const tokenAmount = new BN(amount, 10)
await this.validator.validateUpVoteEffect(id, tokenAmount)
return DiscoverContract.methods
.upvoteEffect(id, amount)
.upvoteEffect(id, tokenAmount.toString())
.call({ from: this.sharedContext.account })
}
@ -104,7 +119,10 @@ class DiscoverService extends BlockchainService {
}
async getDAppById(id) {
let dapp
let dapp = EMPTY_METADATA
const dappExists = await this.isDAppExists(id)
if (dappExists) {
try {
const dappId = await DiscoverContract.methods
.id2index(id)
@ -120,16 +138,18 @@ class DiscoverService extends BlockchainService {
if (dapp.id != id) {
throw new Error('Error fetching correct data from contract')
}
}
return dapp
}
async getDAppDataById(id) {
const dapp = await this.getDAppById(id)
if (dapp.metadata.status == 'EMPTY') return EMPTY_METADATA
try {
const dappMetadata = await MetadataClient.retrieveMetadata(dapp.metadata)
if (dappMetadata === null) return null
if (dappMetadata === null) return EMPTY_METADATA
dapp.metadata = dappMetadata.details
dapp.metadata.status = dappMetadata.status
@ -153,6 +173,7 @@ class DiscoverService extends BlockchainService {
async checkIfCreatorOfDApp(id) {
const dapp = await this.getDAppById(id)
if (dapp.metadata.status == 'EMPTY') return false
this.sharedContext.account = await super.getAccount()
return dapp.developer.toLowerCase() == this.sharedContext.account
@ -174,15 +195,16 @@ class DiscoverService extends BlockchainService {
const uploadedMetadata = await MetadataClient.upload(dappMetadata, email)
let createdTx = null
if (tokenAmount.gt(0)) {
let createdTx = ''
if (tokenAmount.gt(new BN(0, 10))) {
const callData = ConnectedDiscoverContract.methods
.createDApp(dappId, tokenAmount.toString(), uploadedMetadata)
.encodeABI()
createdTx = await this.sharedContext.SNTService.approveAndCall(
this.contract,
tokenAmount.toString(),
tokenAmount,
callData,
)
}
@ -198,7 +220,7 @@ class DiscoverService extends BlockchainService {
await this.validator.validateUpVoting(id, tokenAmount)
const callData = DiscoverContract.methods
.upvote(id, tokenAmount)
.upvote(id, tokenAmount.toString())
.encodeABI()
return this.sharedContext.SNTService.approveAndCall(
this.contract,
@ -216,7 +238,7 @@ class DiscoverService extends BlockchainService {
const tokenAmount = this.decimalMultiplier.mul(amountBN)
const callData = DiscoverContract.methods
.downvote(dapp.id, tokenAmount)
.downvote(dapp.id, tokenAmount.toString())
.encodeABI()
return this.sharedContext.SNTService.approveAndCall(
this.contract,
@ -234,7 +256,8 @@ class DiscoverService extends BlockchainService {
try {
return broadcastContractFn(
ConnectedDiscoverContract.methods.withdraw(id, tokenAmount).send,
ConnectedDiscoverContract.methods.withdraw(id, tokenAmount.toString())
.send,
this.sharedContext.account,
)
} catch (error) {

View File

@ -40,7 +40,11 @@ class SNTService extends BlockchainService {
const ConnectedSNTToken = await super.__unlockServiceAccount(SNTToken)
await this.validator.validateApproveAndCall(spender, amount)
return broadcastContractFn(
ConnectedSNTToken.methods.approveAndCall(spender, amount, callData).send,
ConnectedSNTToken.methods.approveAndCall(
spender,
amount.toString(),
callData,
).send,
this.sharedContext.account,
)
}