Skip to content

Commit

Permalink
Refactoring (#16)
Browse files Browse the repository at this point in the history
* changing get signer implementation

* cleanup

* more build cleanup
  • Loading branch information
cworsnop-figure authored May 11, 2022
1 parent dcc3b0d commit 41b2cee
Show file tree
Hide file tree
Showing 58 changed files with 374 additions and 162 deletions.
19 changes: 0 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,6 @@ subprojects {
}

repositories {
fun figureNexusUsername() = findProperty("nexusUser")?.toString() ?: System.getenv("NEXUS_USER")
fun figureNexusPassword() = findProperty("nexusPass")?.toString() ?: System.getenv("NEXUS_PASS")

maven {
url = uri("https://nexus.figure.com/repository/mirror")
credentials {
username = figureNexusUsername()
password = figureNexusPassword()
}
}
maven {
url = uri("https://nexus.figure.com/repository/figure")
credentials {
username = figureNexusUsername()
password = figureNexusPassword()
}
}

mavenCentral()
}

Expand Down Expand Up @@ -140,7 +122,6 @@ allprojects {
version = semVersion

repositories {
mavenLocal()
mavenCentral()
}
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object Versions {
const val ProvenanceClient = "1.1.1"
const val Unirest = "3.13.6"
const val KeyAccessLib = "0.2.15"
const val LoanPackage = "0.1.10"
const val LoanPackage = "0.1.13"
const val Grpc = "1.45.0"
const val ProvenanceProto = "1.8.0"
const val Reflections = "0.9.10"
Expand Down
2 changes: 1 addition & 1 deletion dc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function publish() {

if [[ -d "$FULL_PATH" ]]; then
pushd $PATH_TO_CONTRACTS > /dev/null
./gradlew p8eClean p8eCheck p8eBootstrap --info && ./gradlew publishToMavenLocal --info
./gradlew p8eClean p8eCheck p8eBootstrap --info && ./gradlew publishToMavenLocal -xsignMavenPublication --info
popd > /dev/null
else
echo "Invalid path. Provide a valid path to the contracts directory you wish to publish."
Expand Down
1 change: 1 addition & 0 deletions models/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
Dependencies.P8eScope.ContractBase,
Dependencies.Provenance.AssetModel,
Dependencies.Kotlin.CoroutinesReactor,
Dependencies.Jackson.Databind,
).forEach { dep ->
dep.implementation(this)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package io.provenance.api.models.account

import io.provenance.scope.contract.proto.Specifications
import java.util.UUID

data class AccountInfo(
val originatorUuid: UUID,
val keyRingIndex: Int = 0,
val keyIndex: Int = 0,
val isTestNet: Boolean = true,
val partyType: Specifications.PartyType = Specifications.PartyType.OWNER,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.provenance.api.models.account

import io.provenance.scope.contract.proto.Specifications
import java.util.UUID

data class Participant(
val uuid: UUID,
val partyType: Specifications.PartyType,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.provenance.api.models.p8e.ProvenanceConfig
import java.time.OffsetDateTime

data class ApproveContractRequest(
val account: AccountInfo,
val account: AccountInfo = AccountInfo(),
val client: ObjectStoreConfig,
val provenanceConfig: ProvenanceConfig,
val envelope: ByteArray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import io.provenance.api.models.p8e.ProvenanceConfig
data class ExecuteContractConfig(
val contract: ContractConfig,
val client: ObjectStoreConfig,
val account: AccountInfo,
val account: AccountInfo = AccountInfo(),
val provenanceConfig: ProvenanceConfig,
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.provenance.api.models.cee

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.account.Participant

data class ExecuteContractRequest(
val config: ExecuteContractConfig,
val records: Map<String, Any>,
val participants: List<AccountInfo> = emptyList()
val participants: List<Participant> = emptyList()
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.eos.ObjectStoreConfig

data class RejectContractRequest(
val account: AccountInfo,
val account: AccountInfo = AccountInfo(),
val client: ObjectStoreConfig,
val rejection: ByteArray,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.p8e.ProvenanceConfig

data class SubmitContractExecutionResultRequest(
val account: AccountInfo,
val account: AccountInfo = AccountInfo(),
val provenance: ProvenanceConfig,
val envelope: ByteArray,
val state: ByteArray,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.onboarding.domain.usecase.provenance.tx.model
package io.provenance.api.models.p8e

data class CreateTxOnboardAssetRequest(
val chainId: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.provenance.onboarding.domain.usecase.provenance.tx.model
package io.provenance.api.models.p8e

import io.provenance.api.models.account.AccountInfo
import io.provenance.onboarding.domain.usecase.common.model.PermissionInfo
import java.util.UUID

data class CreateTxRequest(
val account: AccountInfo,
val account: AccountInfo = AccountInfo(),
val permissions: PermissionInfo?,
val contractSpecId: UUID,
val scopeSpecId: UUID,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.provenance.api.models.p8e

import io.provenance.api.models.account.AccountInfo

data class ExecuteTxRequest(
val account: AccountInfo = AccountInfo(),
val chainId: String,
val nodeEndpoint: String,
val tx: TxBody,
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.onboarding.domain.usecase.common.model
package io.provenance.api.models.p8e

import java.security.PublicKey

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.onboarding.domain.usecase.common.model
package io.provenance.api.models.p8e

import com.fasterxml.jackson.databind.node.ObjectNode

Expand Down
7 changes: 2 additions & 5 deletions service/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ FROM gradle:7.3.3-jdk11 AS build
RUN gradle --version && java -version
WORKDIR /app

ARG NEXUS_USER
ARG NEXUS_PASS

# Only copy dependency-related files
COPY build.gradle.kts gradle.properties settings.gradle.kts buildSrc/build.gradle.kts /app/

# Only download dependencies
# Eat the expected build failure since no source code has been copied yet
RUN gradle clean build -PnexusPass=$NEXUS_PASS -PnexusUser=$NEXUS_USER --no-daemon > /dev/null 2>&1 || true
RUN gradle clean build --no-daemon > /dev/null 2>&1 || true

# Copy all files
COPY service /app/service/
Expand All @@ -22,7 +19,7 @@ COPY build.gradle.kts gradle.properties settings.gradle.kts /app/
COPY CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md LICENSE README.md /app/

# Do the actual build
RUN gradle clean build -PnexusPass=$NEXUS_PASS -PnexusUser=$NEXUS_USER --no-daemon
RUN gradle clean build --no-daemon

FROM openjdk:11-jre

Expand Down
2 changes: 1 addition & 1 deletion service/docker/dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
networks:
- p8e-network
ports:
- "5432:5432"
- "5433:5432"
volumes:
- postgres-cee:/var/lib/postgresql/data
- ./db-init:/docker-entrypoint-initdb.d/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.provenance.api.models.p8e.ProvenanceConfig
import io.provenance.api.models.p8e.TxResponse
import io.provenance.client.grpc.Signer
import io.provenance.metadata.v1.ScopeResponse
import io.provenance.onboarding.domain.usecase.common.model.TxBody
import io.provenance.api.models.p8e.TxBody
import io.provenance.onboarding.frameworks.provenance.ProvenanceTx
import java.util.UUID

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package io.provenance.onboarding.domain.usecase.cee.approve

import com.google.protobuf.Any
import cosmos.tx.v1beta1.TxOuterClass
import io.provenance.api.models.cee.ApproveContractRequest
import io.provenance.onboarding.domain.provenance.Provenance
import io.provenance.onboarding.domain.usecase.AbstractUseCase
import io.provenance.onboarding.domain.usecase.cee.approve.models.ApproveContractRequestWrapper
import io.provenance.onboarding.domain.usecase.cee.common.client.CreateClient
import io.provenance.onboarding.domain.usecase.cee.common.client.model.CreateClientRequest
import io.provenance.onboarding.domain.usecase.provenance.account.GetSigner
Expand All @@ -17,17 +17,17 @@ class ApproveContractExecution(
private val createClient: CreateClient,
private val provenance: Provenance,
private val getSigner: GetSigner,
) : AbstractUseCase<ApproveContractRequest, Unit>() {
override suspend fun execute(args: ApproveContractRequest) {
val client = createClient.execute(CreateClientRequest(args.account, args.client))
val envelope = Envelopes.Envelope.newBuilder().mergeFrom(args.envelope).build()
) : AbstractUseCase<ApproveContractRequestWrapper, Unit>() {
override suspend fun execute(args: ApproveContractRequestWrapper) {
val client = createClient.execute(CreateClientRequest(args.uuid, args.request.account, args.request.client))
val envelope = Envelopes.Envelope.newBuilder().mergeFrom(args.request.envelope).build()

when (val result = client.execute(envelope)) {
is FragmentResult -> {
val approvalTxHash = client.approveScopeUpdate(result.envelopeState, args.expiration).let {
val signer = getSigner.execute(args.account)
val approvalTxHash = client.approveScopeUpdate(result.envelopeState, args.request.expiration).let {
val signer = getSigner.execute(args.uuid)
val txBody = TxOuterClass.TxBody.newBuilder().addAllMessages(it.map { msg -> Any.pack(msg, "") }).build()
val broadcast = provenance.executeTransaction(args.provenanceConfig, txBody, signer)
val broadcast = provenance.executeTransaction(args.request.provenanceConfig, txBody, signer)

broadcast.txhash
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.provenance.onboarding.domain.usecase.cee.approve.models

import io.provenance.api.models.cee.ApproveContractRequest
import java.util.UUID

data class ApproveContractRequestWrapper(
val uuid: UUID,
val request: ApproveContractRequest
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.provenance.core.KeyType
import io.provenance.onboarding.domain.usecase.AbstractUseCase
import io.provenance.onboarding.domain.usecase.cee.common.client.model.CreateClientRequest
import io.provenance.onboarding.domain.usecase.common.originator.GetOriginator
import io.provenance.onboarding.frameworks.config.ProvenanceProperties
import io.provenance.scope.encryption.model.DirectKeyRef
import io.provenance.scope.encryption.util.toJavaPublicKey
import io.provenance.scope.sdk.Affiliate
Expand All @@ -19,10 +20,11 @@ import java.util.concurrent.TimeUnit

@Component
class CreateClient(
private val getOriginator: GetOriginator
private val getOriginator: GetOriginator,
private val provenanceProperties: ProvenanceProperties,
) : AbstractUseCase<CreateClientRequest, Client>() {
override suspend fun execute(args: CreateClientRequest): Client {
val originator = getOriginator.execute(args.account.originatorUuid)
val originator = getOriginator.execute(args.uuid)
val affiliate = Affiliate(
signingKeyRef = DirectKeyRef(KeyPair(originator.signingPublicKey() as PublicKey, originator.signingPrivateKey() as PrivateKey)),
encryptionKeyRef = DirectKeyRef(KeyPair(originator.encryptionPublicKey() as PublicKey, originator.encryptionPrivateKey() as PrivateKey)),
Expand All @@ -31,11 +33,11 @@ class CreateClient(

val sharedClient = SharedClient(
ClientConfig(
mainNet = !args.account.isTestNet,
mainNet = provenanceProperties.mainnet,
cacheJarSizeInBytes = 4L * 1024 * 1024, // ~ 4 MB,
cacheRecordSizeInBytes = 0L,
cacheSpecSizeInBytes = 0L,
disableContractLogs = !args.account.isTestNet,
disableContractLogs = provenanceProperties.mainnet,
osConcurrencySize = 6,
osGrpcUrl = URI(args.client.objectStoreUrl),
osChannelCustomizeFn = { channelBuilder ->
Expand All @@ -47,7 +49,7 @@ class CreateClient(
)
).also { client ->
args.affiliates.forEach {
val keys = getOriginator.execute(it.originatorUuid).keys
val keys = getOriginator.execute(it.uuid).keys
client.affiliateRepository.addAffiliate(keys[KeyType.SIGNING_PUBLIC_KEY].toString().toJavaPublicKey(), keys[KeyType.ENCRYPTION_PUBLIC_KEY].toString().toJavaPublicKey())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.provenance.onboarding.domain.usecase.cee.common.client.model

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.account.Participant
import io.provenance.api.models.eos.ObjectStoreConfig
import java.util.UUID

data class CreateClientRequest(
val account: AccountInfo,
val uuid: UUID,
val account: AccountInfo = AccountInfo(),
val client: ObjectStoreConfig,
val affiliates: List<AccountInfo> = emptyList(),
val affiliates: List<Participant> = emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.provenance.onboarding.domain.usecase.cee.execute

import com.google.protobuf.Message
import io.provenance.api.models.cee.ContractExecutionResponse
import io.provenance.api.models.cee.ExecuteContractRequest
import io.provenance.api.models.p8e.TxResponse
import io.provenance.client.protobuf.extensions.isSet
import io.provenance.metadata.v1.ScopeResponse
Expand All @@ -12,6 +11,7 @@ import io.provenance.onboarding.domain.provenance.Provenance
import io.provenance.onboarding.domain.usecase.AbstractUseCase
import io.provenance.onboarding.domain.usecase.cee.common.client.CreateClient
import io.provenance.onboarding.domain.usecase.cee.common.client.model.CreateClientRequest
import io.provenance.onboarding.domain.usecase.cee.execute.model.ExecuteContractRequestWrapper
import io.provenance.onboarding.domain.usecase.common.originator.GetOriginator
import io.provenance.onboarding.domain.usecase.provenance.account.GetSigner
import io.provenance.onboarding.frameworks.provenance.SingleTx
Expand All @@ -35,26 +35,26 @@ class ExecuteContract(
private val contractParser: ContractParser,
private val createClient: CreateClient,
private val getOriginator: GetOriginator,
) : AbstractUseCase<ExecuteContractRequest, Any>() {
) : AbstractUseCase<ExecuteContractRequestWrapper, Any>() {

override suspend fun execute(args: ExecuteContractRequest): ContractExecutionResponse {
val signer = getSigner.execute(args.config.account)
val client = createClient.execute(CreateClientRequest(args.config.account, args.config.client, args.participants))
val contract = contractService.getContract(args.config.contract.contractName)
val records = getRecords(args.records, contract)
override suspend fun execute(args: ExecuteContractRequestWrapper): ContractExecutionResponse {
val signer = getSigner.execute(args.uuid)
val client = createClient.execute(CreateClientRequest(args.uuid, args.request.config.account, args.request.config.client, args.request.participants))
val contract = contractService.getContract(args.request.config.contract.contractName)
val records = getRecords(args.request.records, contract)

val participants = args.participants.associate {
it.partyType to getOriginator.execute(it.originatorUuid)
val participants = args.request.participants.associate {
it.partyType to getOriginator.execute(it.uuid)
}

val scope = provenanceService.getScope(args.config.provenanceConfig, args.config.contract.scopeUuid)
val scope = provenanceService.getScope(args.request.config.provenanceConfig, args.request.config.contract.scopeUuid)
val scopeToUse: ScopeResponse? = if (scope.scope.scope.isSet() && !scope.scope.scope.scopeId.isEmpty) scope else null
val session = contractService.setupContract(client, contract, records, args.config.contract.scopeUuid, args.config.contract.sessionUuid, participants, scopeToUse, args.config.contract.scopeSpecificationName)
val session = contractService.setupContract(client, contract, records, args.request.config.contract.scopeUuid, args.request.config.contract.sessionUuid, participants, scopeToUse, args.request.config.contract.scopeSpecificationName)

return when (val result = contractService.executeContract(client, session)) {
is SignedResult -> {
provenanceService.buildContractTx(args.config.provenanceConfig, SingleTx(result))?.let {
provenanceService.executeTransaction(args.config.provenanceConfig, it, signer).let { pbResponse ->
provenanceService.buildContractTx(args.request.config.provenanceConfig, SingleTx(result))?.let {
provenanceService.executeTransaction(args.request.config.provenanceConfig, it, signer).let { pbResponse ->
ContractExecutionResponse(false, null, TxResponse(pbResponse.txhash, pbResponse.gasWanted.toString(), pbResponse.gasUsed.toString(), pbResponse.height.toString()))
}
} ?: throw IllegalStateException("Failed to build contract for execution output.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.provenance.onboarding.domain.usecase.cee.execute.model

import io.provenance.api.models.cee.ExecuteContractRequest
import java.util.UUID

data class ExecuteContractRequestWrapper(
val uuid: UUID,
val request: ExecuteContractRequest,
)
Loading

0 comments on commit 41b2cee

Please sign in to comment.