Skip to content

Commit

Permalink
Asset Classification / Misc (#29)
Browse files Browse the repository at this point in the history
* Adding participants to audience keys

* stashing

* initial pass working

* minor cleanup

* more cleanup

* Update README.md

* misc fixes

* Update service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/contracts/fees/GetFeesForAsset.kt

Co-authored-by: Ravi Patel <[email protected]>

* Update service/src/main/kotlin/io/provenance/api/frameworks/web/external/provenance/ProvenanceApi.kt

Co-authored-by: Ravi Patel <[email protected]>

* PR comments

* build fixes from merge

Co-authored-by: Ravi Patel <[email protected]>
  • Loading branch information
cworsnop-figure and rpatel-figure authored Jun 3, 2022
1 parent 8934197 commit 9e53c75
Show file tree
Hide file tree
Showing 59 changed files with 802 additions and 128 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ brew install docker
brew tap hashicorp/tap
brew install hashicorp/tap/vault
```
If you plan on running smart contracts for asset classification you'll need the following:
```
brew install rust
brew install jq
```

You'll additionally need `CoreUtils` if your system is missing it:
```
brew install coreutils
```
**Note: it's possible to install all dependencies with the following command:**
```
./dc.sh setup
```

The default configuration assumes that the following ports are available:

Expand Down
8 changes: 7 additions & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ object Versions {
const val ProvenanceClient = "1.1.1"
const val Unirest = "3.13.6"
const val KeyAccessLib = "0.2.17"
const val LoanPackage = "0.1.16"
const val LoanPackage = "0.1.17"
const val Grpc = "1.45.0"
const val ProvenanceProto = "1.8.0"
const val Reflections = "0.9.10"
const val NexusPublishing = "1.1.0"
const val BouncyCastle = "1.70"
const val OpenApi = "1.5.13"
const val TestContainer = "1.3.3"
const val AssetClassification = "1.2.0-rc4"
}

object Plugins { // please keep this sorted in sections
Expand Down Expand Up @@ -89,6 +90,11 @@ object Dependencies {
)
}

object AssetClassification {
val Client = DependencySpec("io.provenance.classification.asset:ac-client", Versions.AssetClassification)
val Verifier = DependencySpec("io.provenance.classification.asset:ac-verifier", Versions.AssetClassification)
}

object P8eScope {
val Encryption = DependencySpec("io.provenance.scope:encryption", Versions.P8eScope)
val OsClient = DependencySpec("io.provenance.scope:os-client", Versions.P8eScope)
Expand Down
81 changes: 77 additions & 4 deletions dc.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#!/bin/bash

while getopts 'p:' OPTION; do
while getopts 'p: c' OPTION; do
case "$OPTION" in
p)
PATH_TO_CONTRACTS="$OPTARG"
echo "Path to contracts you wish to publish: $OPTARG"
;;
c)
SETUP_SMART_CONTRACT=true
echo "Running setup with smart contracts."
;;
?)
echo "script usage: $(basename \$0) [-p <path to p8e contracts directory>]" >&2
exit 1
Expand All @@ -15,9 +19,6 @@ done
shift "$(($OPTIND -1))"

function up {
#config vault
sh service/docker/vault/config.sh

docker-compose -p p8e-contract-execution-environment -f service/docker/dependencies.yaml up --build -d

sleep 2
Expand All @@ -43,6 +44,11 @@ function up {
"jealous bright oyster fluid guide talent crystal minor modify broken stove spoon pen thank action smart enemy chunk ladder soon focus recall elite pulp"

docker ps -a

if [ "$SETUP_SMART_CONTRACT" = true ]; then
echo "Setting up smart contracts!"
upload_classification_contract
fi
}

function publish() {
Expand Down Expand Up @@ -73,4 +79,71 @@ function bounce {
up
}

function build_classification() {
if [ -z ${PATH_TO_CONTRACTS+x} ]; then
echo "Provide a valid path to the smart contracts directory you wish to store on provenance using the -p argument."
exit
fi

export FULL_PATH=$(realpath $PATH_TO_CONTRACTS)

if [[ -d "$PATH_TO_CONTRACTS" ]]; then
pushd $PATH_TO_CONTRACTS > /dev/null
cargo build
make optimize
popd > /dev/null
cp $PATH_TO_CONTRACTS/artifacts/asset_classification_smart_contract.wasm service/docker/prov-init/contracts/asset_classification_smart_contract.wasm
else
echo "Invalid path. Provide a valid path to the contracts directory you wish to publish."
fi
}

function setup() {
brew install docker
brew tap hashicorp/tap
brew install hashicorp/tap/vault
brew install rust
brew install jq
brew install coreutils
}

function upload_classification_contract() {
echo "Uploading contract to provenance!"
upload=$(docker exec provenance provenanced tx wasm store contracts/asset_classification_smart_contract.wasm \
--instantiate-only-address tp1v5d9uek3qwqh25yrchj20mkgrksdfyyxhnsdag \
--from tp1v5d9uek3qwqh25yrchj20mkgrksdfyyxhnsdag \
--chain-id chain-local \
--gas auto \
--gas-prices="1905nhash" \
--gas-adjustment=1.2 \
--broadcast-mode block \
--testnet \
--output json \
--yes)

code_id=$(echo $upload | jq -r '.logs[] | select(.msg_index == 0) | .events[] | select(.type == "store_code") | .attributes[0].value')
echo "Upload complete. Code id: $code_id"
instantiate=$(docker exec provenance provenanced tx wasm instantiate $code_id \
'{
"base_contract_name": "assetclassificationalias.pb",
"bind_base_name": true,
"asset_definitions": '"$(cat service/docker/prov-init/contracts/asset_definitions.json)"',
"is_test": true
}' \
--admin "tp1v5d9uek3qwqh25yrchj20mkgrksdfyyxhnsdag" \
--from tp1v5d9uek3qwqh25yrchj20mkgrksdfyyxhnsdag \
--label examples \
--chain-id chain-local \
--gas auto \
--gas-prices="1905nhash" \
--gas-adjustment=1.2 \
--broadcast-mode block \
--testnet \
--output json \
--yes | jq)

contract_address=$(echo $instantiate | jq '.logs[] | select(.msg_index == 0) | .events[] | select(.type == "instantiate") | .attributes[] | select(.key == "_contract_address") | .value')
echo "Asset classification contract fully setup! contract address: $contract_address"
}

${1}
2 changes: 2 additions & 0 deletions models/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ dependencies {
Dependencies.P8eScope.OsClient,
Dependencies.Kotlin.CoroutinesReactor,
Dependencies.Jackson.Databind,
Dependencies.AssetClassification.Client,
Dependencies.AssetClassification.Verifier,
).forEach { dep ->
dep.implementation(this)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.models.cee
package io.provenance.api.models.cee.approve

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.eos.ObjectStoreConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.models.cee
package io.provenance.api.models.cee.execute

import io.provenance.api.models.p8e.TxResponse

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.provenance.api.models.cee
package io.provenance.api.models.cee.execute

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.cee.ContractConfig
import io.provenance.api.models.eos.ObjectStoreConfig
import io.provenance.api.models.p8e.ProvenanceConfig

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.models.cee
package io.provenance.api.models.cee.execute

import io.provenance.api.models.account.Participant
import io.provenance.api.models.p8e.PermissionInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.models.cee
package io.provenance.api.models.cee.reject

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.eos.ObjectStoreConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.models.cee
package io.provenance.api.models.cee.submit

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.p8e.ProvenanceConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.models.eos
package io.provenance.api.models.eos.get

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.models.eos
package io.provenance.api.models.eos.get

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.models.eos
package io.provenance.api.models.eos.store

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.p8e.PermissionInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.models.eos
package io.provenance.api.models.eos.store

import io.provenance.objectstore.proto.Objects
import java.util.Base64
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.provenance.api.models.p8e.contracts

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

data class ClassifyAssetRequest(
val provenanceConfig: ProvenanceConfig,
val contractConfig: SmartContractConfig,
val account: AccountInfo = AccountInfo(),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.provenance.api.models.p8e.contracts

import io.provenance.classification.asset.client.domain.model.AccessRoute
import java.util.UUID

data class SmartContractConfig(
val contractName: String,
val assetUuid: UUID,
val assetType: String = "",
val verifierAddress: String,
val accessRoutes: List<AccessRoute> = emptyList()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.provenance.api.models.p8e.contracts

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

data class VerifyAssetRequest(
val provenanceConfig: ProvenanceConfig,
val contractConfig: SmartContractConfig,
val account: AccountInfo = AccountInfo(),
val message: String,
val success: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.provenance.api.models.p8e.query

import java.util.UUID

data class QueryScopeRequest(
val uuid: UUID,
val scopeUuid: UUID,
val chainId: String,
val nodeEndpoint: String,
val objectStoreUrl: String,
val height: Long? = null,
val hydrate: Boolean = false,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.provenance.api.models.p8e
package io.provenance.api.models.p8e.tx

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.p8e.PermissionInfo
import java.util.UUID

data class CreateTxRequest(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.provenance.api.models.p8e
package io.provenance.api.models.p8e.tx

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

data class ExecuteTxRequest(
val account: AccountInfo = AccountInfo(),
Expand Down
2 changes: 2 additions & 0 deletions service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ dependencies {
Dependencies.BouncyCastleProvider,
Dependencies.OpenApi.WebFluxSupport,
Dependencies.OpenApi.KotlinSupport,
Dependencies.AssetClassification.Client,
Dependencies.AssetClassification.Verifier,

).forEach { dep ->
dep.implementation(this)
Expand Down
9 changes: 4 additions & 5 deletions service/docker/dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ services:
ports:
- "8200:8200"
restart: always
volumes:
- ./volumes/logs:/vault/logs
- ./volumes/file:/vault/file
- ./volumes/config:/vault/config
environment:
- VAULT_DEV_ROOT_TOKEN_ID=root
- VAULT_DEV_LISTEN_ADDRESS=0.0.0.0:8200
cap_add:
- IPC_LOCK
entrypoint: vault server -config=/vault/config/vault.json
entrypoint: vault server -dev

volumes:
postgres-cee:
Expand Down
29 changes: 29 additions & 0 deletions service/docker/prov-init/contracts/asset_definitions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"asset_type": "mortgage",
"scope_spec_identifier": {
"type": "uuid",
"value": "c370d852-0f3b-4f70-85e6-25983ac07c0f"
},
"verifiers": [
{
"address": "tp1mryqzguyelef5dae7k6l22tnls93cvrc60tjdc",
"onboarding_cost": "243857142857",
"onboarding_denom": "nhash",
"fee_destinations": [
{
"address": "tp1mryqzguyelef5dae7k6l22tnls93cvrc60tjdc",
"fee_amount": "1000000000"
}
],
"entity_detail": {
"name": "Figure Mortgage Verifier",
"description": "Validates onboarded Mortgage Assets",
"home_url": "https://www.figure.com",
"source_url": "https://github.com/FigureTechnologies/asset-classification-verifier"
}
}
],
"enabled": true
}
]
23 changes: 0 additions & 23 deletions service/docker/vault/config.sh

This file was deleted.

Loading

0 comments on commit 9e53c75

Please sign in to comment.