Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data access #64

Open
wants to merge 17 commits into
base: os-locator
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Using more of a kotlin style in handling some functions
  • Loading branch information
wbaker-figure committed Jun 30, 2021
commit b68bb0b74feaedccbf4f402f9ee0f2e3c13638b9
Original file line number Diff line number Diff line change
@@ -125,30 +125,7 @@ class IndexHandler(
)
// If the env is the invoker, create the data access message and put into a job.
if(envelope.isInvoker == true && envelope.data.input.affiliateSharesList.isNotEmpty()) {
val envelopeDataAccess = envelope.data.input.affiliateSharesList.map {
affiliateService.getAddress(
it.toPublicKey(), chaincodeProperties.mainNet
)
}
val existingScopeDataAccess = provenanceGrpcService.retrieveScopeData(envelope.data.input.scope.uuid.value).scope.scope.dataAccessList
// Only perform job if data access will be updated
if (envelopeDataAccess.any { it !in existingScopeDataAccess }) {
p8e.Jobs.MsgAddScopeDataAccessRequest.newBuilder()
.addAllDataAccess(envelopeDataAccess)
.addAllSigners(envelope.data.result.signaturesList.map {
it.signer.signingPublicKey.toPublicKey().let {
affiliateService.getAddress(it, chaincodeProperties.mainNet)
}
})
.setScopeId(
envelope.data.input.ref.scopeUuid.value.toUuidProv().toAddress(
PROV_METADATA_PREFIX_SCOPE_ADDR
).toByteString()
)
.setPublicKey(envelope.data.input.contract.invoker.encryptionPublicKey)
.build().takeIf { envelope.data.input.affiliateSharesList.isNotEmpty() }
?.let { dataAccessService.addDataAccess(it) }
}
updateDataAccess(envelope)
}
} else {
log.warn("Skipping ES indexing for stale scope")
@@ -205,4 +182,35 @@ class IndexHandler(
request.opType(OpType.INDEX)
return request
}

private fun updateDataAccess(envelope: EnvelopeRecord) {
val envelopeDataAccess = envelope.data.input.affiliateSharesList.map {
affiliateSharePublicKey ->
affiliateService.getAddress(
affiliateSharePublicKey.toPublicKey(), chaincodeProperties.mainNet
// it.toPublicKey(), chaincodeProperties.mainNet
wbaker-figure marked this conversation as resolved.
Show resolved Hide resolved
)
}
val existingScopeDataAccess = provenanceGrpcService.retrieveScopeData(envelope.data.input.scope.uuid.value).scope.scope.dataAccessList
// Only perform job if data access will be updated
if (envelopeDataAccess.any { it !in existingScopeDataAccess }) {
p8e.Jobs.MsgAddScopeDataAccessRequest.newBuilder()
.addAllDataAccess(envelopeDataAccess)
.addAllSigners(envelope.data.result.signaturesList.map {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By any chance did you test this with a multiparty contract? I'm not positive, but I think the only signer we want is the scope owner. In the case for our scopes that's always a single invoker. If you only ran single party contracts, the envelope.data.result.signaturesList should only contain the invoker so it's not a big deal. It would take a multiparty contract to see if this fails or not as is.

signature ->
signature.signer.signingPublicKey.toPublicKey().let {
signerPublicKey ->
affiliateService.getAddress(signerPublicKey, chaincodeProperties.mainNet)
}
})
.setScopeId(
envelope.data.input.ref.scopeUuid.value.toUuidProv().toAddress(
PROV_METADATA_PREFIX_SCOPE_ADDR
).toByteString()
)
.setPublicKey(envelope.data.input.contract.invoker.encryptionPublicKey)
.build().takeIf { envelope.data.input.affiliateSharesList.isNotEmpty() }
?.let { dataAccessService.addDataAccess(it) }
}
}
}
Original file line number Diff line number Diff line change
@@ -21,6 +21,9 @@ import p8e.Jobs
import java.security.KeyPair
import java.security.PublicKey

// One to One Billion ratio from hash to nhash
private const val HASH_TO_NHASH = 1000000000L

@Service
class DataAccessChaincodeService(
private val chaincodeProperties: ChaincodeProperties,
@@ -54,9 +57,11 @@ class DataAccessChaincodeService(
)

// perform and wait for hash transfer to complete if account has less than 10 hash
if (provenanceGrpcService.getAccountCoins(affiliateAddress)[0].amount.toLong() / 1000000000 < 10) {
if ((provenanceGrpcService.getAccountCoins(affiliateAddress).find {it.denom == "nhash"}?.amount?.toLong()
?: 0L) / HASH_TO_NHASH < 10
) {
waitForTx {
transferHash(affiliateAccount.address, 10000000000)
transferHash(affiliateAccount.address, 100 * HASH_TO_NHASH)
}
}
val resp = provenanceGrpcService.batchTx(