Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

Candidate for V0.1.2 #7

Merged
merged 9 commits into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 38 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ This is all the information required to identify a wallet address with a cognome

Assume the wallet address is

```
```bash
addr1qxvlcxj3fg3jk2dp3kmkxhnx2zuv7edktk5rfy2n9juj3h2m0cw9csycjc4v59ywy7fk8nqfu6qjdzjejhvayfhf8dwsttnjt6
```

then the hash representation is

```
```bash
0199fc1a514a232b29a18db7635e6650b8cf65b65da83491532cb928dd5b7e1c5c4098962aca148e279363cc09e681268a5995d9d226e93b5d
```

Expand Down Expand Up @@ -88,12 +88,46 @@ For this example address, the datum will become
]
}
```
The other information contained in the datum are for holding information to create a custom profile for the cogno.
The datum above is the default cogno profile for a new user. The other entries in the datum are designated for information used to create a custom profile for the cogno.

## Use Case

When a wallet address is queried, the wallet address can be cross reference with datum data from this contract to relay information about that specific wallet. This behaves very similarly to already existing NFT based identification but the key difference is the updatable data and that it can be referenced on-chain. Smart contracts will now have the ability to reference a wallets Cogno and use that data in on-chain validation functions.

# tag

TODO
The tag data structure is designed for displaying and connecting messages on the blockchain. Similarly to the cogno data, a wallet owns the utxo that holds their message. The tag data holds a tag, a short title or label for the post, the details of the post, and if applicable a quote, the txId information of a previous post.

```hs
data TagData = TagData
{ tPkh :: PlutusV2.PubKeyHash
-- ^ The public key hash of the wallet.
, tSc :: PlutusV2.PubKeyHash
-- ^ The stake hash of the wallet.
, tTag :: PlutusV2.BuiltinByteString
-- ^ The tag of the message.
, tDetail :: [PlutusV2.BuiltinByteString]
-- ^ The details of the message.
, tQuoteTxId :: PlutusV2.BuiltinByteString
-- ^ The TxId of the quote tag.
, tQuoteIndex :: Integer
-- ^ The Index of the quote tag.
}
```
The user may decide to remove the tag after tagging or they may just update an already existing tag with a new message. The message is permanent and available to all on the blockchain.

Another user may see a tag and quote it in their own tag. This type of tag referencing is very similar to commenting to someone elses message on social media. The type of quoting system allows for a direct pointer to the utxo of a previous tag, allowing for dynamic connections to made while all being referencable on-chain.

Any wallet may make a tag but if a tagger happens to have a cogno then their data will be connected and the profile will be shown with their post. This allows public profiles to exist while permitting pseudo-anonymous taggers.

## Use Case

Tagging the chain with messages can work as a social media dApp or as a data aggregation portal for oracles. The key aspect about the tagging system is the cogno connections. On chain data structures can be linked to off chain profiles that are held on chain.

![Cogno connecting with a Tag](./images/cogno-tag-connection.png)

There are many cogno and many tags but the connections between them reveal a wallet profile that can be shown off chain. The connection is displayed above by the yellow arrows indicating a network betwen a cogno, a tag, and a quote. This information may be used to relay the cogno information for a frontend website to use.

# Other Data

Any new data structure may be added to the ecosystem along side the cogno and tag structures.
2 changes: 1 addition & 1 deletion cogno-contract/cogno-contract.plutus

Large diffs are not rendered by default.

56 changes: 30 additions & 26 deletions cogno-contract/src/CognoContract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Cardano.Api.Shelley ( PlutusScript (..), PlutusScrip
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Short as SBS
import qualified Plutus.V1.Ledger.Scripts as Scripts
import qualified Plutus.V1.Ledger.Value as Value
import qualified Plutus.V1.Ledger.Value as Value
import qualified Plutus.V2.Ledger.Api as PlutusV2
import qualified Plutus.V2.Ledger.Contexts as ContextsV2
import Plutus.Script.Utils.V2.Scripts as Utils
Expand All @@ -55,6 +55,9 @@ import HelperFunctions

The Glorious Glasgow Haskell Compilation System, version 8.10.7
-}
-------------------------------------------------------------------------------
-- | The minimum value of ADA in a wallet to update a cogno. 10 ADA
-------------------------------------------------------------------------------
thresholdLovelace :: Integer
thresholdLovelace = 10000000
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -84,81 +87,82 @@ mkValidator :: CustomDatumType -> CustomRedeemerType -> PlutusV2.ScriptContext -
mkValidator datum redeemer context =
case datum of
-- the tag state
(Tag td) ->
( Tag td ) ->
let userPkh = tPkh td
userAddr = createAddress userPkh (tSc td)
in case redeemer of
-- remove utxo from the contract
-- remove utxo from the contract and send to user's address
Remove -> do
{ let a = traceIfFalse "Incorrect In/Out" $ isNInputs txInputs 1 && isNOutputs contTxOutputs 0 -- single input no outputs
; let b = traceIfFalse "Wrong Tx Signer" $ ContextsV2.txSignedBy info userPkh -- wallet must sign it
; let c = traceIfFalse "Value Not Paid" $ isAddrGettingPaid txOutputs userAddr validatingValue -- send back the leftover
; traceIfFalse "Tag Remove Error" $ all (==(True :: Bool)) [a,b,c]
}

-- update the utxo datum
-- update the utxo datum and send the utxo back to the contract
Update ->
case getOutboundDatum contTxOutputs validatingValue of
Nothing -> False
Just outboundDatum ->
case outboundDatum of
(Tag td') -> do
( Tag td' ) -> do
{ let a = traceIfFalse "Incorrect In/Out" $ isNInputs txInputs 1 && isNOutputs contTxOutputs 1 -- single input single output
; let b = traceIfFalse "Wrong Tx Signer" $ ContextsV2.txSignedBy info userPkh -- wallet must sign it
; let c = traceIfFalse "Incorrect Datum" $ updateTagData td td' -- the datum changes correctly
; traceIfFalse "Tag Update Error" $ all (==(True :: Bool)) [a,b,c]
}

-- only tag
-- only tag datum
_ -> False
-- only remove or update
-- only remove or update redeemers
_ -> False

-- the cogno state
(Cogno cd) ->
( Cogno cd ) ->
let userPkh = cdPkh cd
userAddr = createAddress userPkh (cdSc cd)
in case redeemer of
-- remove utxo from the contract
-- remove utxo from the contract and send it back to the user's address
Remove -> do
{ let a = traceIfFalse "Incorrect In/Out" $ isNInputs txInputs 1 && isNOutputs contTxOutputs 0 -- single input no outputs
; let b = traceIfFalse "Wrong Tx Signer" $ ContextsV2.txSignedBy info userPkh -- wallet must sign it
; let c = traceIfFalse "Value Not Paid" $ isAddrGettingPaid txOutputs userAddr validatingValue -- send back the leftover
; traceIfFalse "Cogno Remove Error" $ all (==(True :: Bool)) [a,b,c]
; traceIfFalse "Cogno Remove Error" $ all (==True) [a,b,c]
}

-- update the utxo datum
-- update the utxo datum and send it back to the contract
Update ->
case getOutboundDatum contTxOutputs validatingValue of
Nothing -> False
Just outboundDatum ->
case outboundDatum of
(Cogno cd') -> do
( Cogno cd' ) -> do
{ let a = traceIfFalse "Incorrect In/Out" $ isNInputs txInputs 1 && isNOutputs contTxOutputs 1 -- single input single output
; let b = traceIfFalse "Wrong Tx Signer" $ ContextsV2.txSignedBy info userPkh -- wallet must sign it
; let c = traceIfFalse "Incorrect Datum" $ updateCognoData cd cd' -- the datum changes correctly
; let d = traceIfFalse "Minimum Value" $ Value.geq validatingValue minimumValue -- Must have minimum value
; traceIfFalse "Cogno Update Error" $ all (==(True :: Bool)) [a,b,c,d]
; traceIfFalse "Cogno Update Error" $ all (==True) [a,b,c,d]
}

-- only cogno
-- only cogno datum
_ -> False

-- anyone can give a kudos
-- anyone can give a kudos by spending a profile back to the contract with a + 1 kudos.
Kudos ->
case getOutboundDatum contTxOutputs validatingValue of
Nothing -> False
Just outboundDatum ->
case outboundDatum of
(Cogno cd') -> do
{ let a = traceIfFalse "Incorrect In/Out" $ isNInputs txInputs 1 && isNOutputs contTxOutputs 1 -- single input single output
; let b = traceIfFalse "Incorrect Datum" $ giveAKudo cd cd' -- the datum changes correctly
; let c = traceIfFalse "Minimum Value" $ Value.geq validatingValue minimumValue -- Must have minimum value
; traceIfFalse "Cog Update Error" $ all (==(True :: Bool)) [a,b,c]
( Cogno cd' ) -> do
{ let a = traceIfFalse "Incorrect In/Out" $ isNInputs txInputs 1 && isNOutputs contTxOutputs 1 -- single input single output
; let b = traceIfFalse "Incorrect Datum" $ giveAKudo cd cd' -- the datum changes correctly
; let c = traceIfFalse "Minimum Value" $ Value.geq validatingValue minimumValue -- Must have minimum value
; traceIfFalse "Cogno Update Error" $ all (==True) [a,b,c]
}

-- only cogno
-- only cogno datum
_ -> False
-- end of case datum
where
info :: PlutusV2.TxInfo
info = ContextsV2.scriptContextTxInfo context
Expand All @@ -180,9 +184,9 @@ mkValidator datum redeemer context =
Nothing -> traceError "" -- This error should never be hit.
Just input -> PlutusV2.txOutValue $ PlutusV2.txInInfoResolved input

-- threshold ada amount to do things, 10 ada
-- | threshold ada amount to do things, 10 ada
minimumValue :: PlutusV2.Value
minimumValue = Value.singleton Value.adaSymbol Value.adaToken thresholdLovelace
minimumValue = Value.singleton Value.adaSymbol Value.adaToken thresholdLovelace -- defined near top of file

-- | Get the inline datum that holds a value from a list of tx outs.
getOutboundDatum :: [PlutusV2.TxOut] -> PlutusV2.Value -> Maybe CustomDatumType
Expand All @@ -191,11 +195,11 @@ mkValidator datum redeemer context =
if PlutusV2.txOutValue x == val -- strict value continue
then
case PlutusV2.txOutDatum x of
PlutusV2.NoOutputDatum -> Nothing -- forbid null datums
(PlutusV2.OutputDatumHash _) -> Nothing -- forbid embedded datums
PlutusV2.NoOutputDatum -> Nothing -- forbid null datums
( PlutusV2.OutputDatumHash _ ) -> Nothing -- forbid embedded datums

-- inline datum only
(PlutusV2.OutputDatum (PlutusV2.Datum d)) ->
( PlutusV2.OutputDatum ( PlutusV2.Datum d )) ->
case PlutusTx.fromBuiltinData d of
Nothing -> getOutboundDatum xs val
Just inline -> Just $ PlutusTx.unsafeFromBuiltinData @CustomDatumType inline
Expand Down
18 changes: 9 additions & 9 deletions cogno-contract/src/HelperFunctions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ import qualified Plutus.V2.Ledger.Api as PlutusV2
createAddress :: PlutusV2.PubKeyHash -> PlutusV2.PubKeyHash -> PlutusV2.Address
createAddress pkh sc =
if PlutusV2.getPubKeyHash sc == emptyByteString
then PlutusV2.Address (PubKeyCredential pkh) Nothing
else PlutusV2.Address (PubKeyCredential pkh) (Just $ StakingHash $ PubKeyCredential sc)
then PlutusV2.Address ( PubKeyCredential pkh ) Nothing
else PlutusV2.Address ( PubKeyCredential pkh ) ( Just $ StakingHash $ PubKeyCredential sc )

-------------------------------------------------------------------------------
-- | Search each TxOut for an addr and value.
-------------------------------------------------------------------------------
isAddrGettingPaid :: [PlutusV2.TxOut] -> PlutusV2.Address -> PlutusV2.Value -> Bool
isAddrGettingPaid [] _ _ = False
isAddrGettingPaid [] _ _ = False
isAddrGettingPaid (x:xs) addr val
| checkAddr && checkVal = True
| otherwise = isAddrGettingPaid xs addr val
Expand All @@ -72,9 +72,9 @@ isNInputs utxos number = loopInputs utxos 0
loopInputs [] counter = counter == number
loopInputs (x:xs) counter =
case PlutusV2.txOutDatum $ PlutusV2.txInInfoResolved x of
PlutusV2.NoOutputDatum -> loopInputs xs counter
(PlutusV2.OutputDatumHash _) -> loopInputs xs (counter + 1)
(PlutusV2.OutputDatum _) -> loopInputs xs (counter + 1)
PlutusV2.NoOutputDatum -> loopInputs xs counter
( PlutusV2.OutputDatumHash _ ) -> loopInputs xs ( counter + 1 )
( PlutusV2.OutputDatum _ ) -> loopInputs xs ( counter + 1 )

-------------------------------------------------------------------------------
-- | Count the number of outputs that have datums of any kind.
Expand All @@ -86,6 +86,6 @@ isNOutputs utxos number = loopInputs utxos 0
loopInputs [] counter = counter == number
loopInputs (x:xs) counter =
case PlutusV2.txOutDatum x of
PlutusV2.NoOutputDatum -> loopInputs xs counter
(PlutusV2.OutputDatumHash _) -> loopInputs xs (counter + 1)
(PlutusV2.OutputDatum _) -> loopInputs xs (counter + 1)
PlutusV2.NoOutputDatum -> loopInputs xs counter
( PlutusV2.OutputDatumHash _ ) -> loopInputs xs ( counter + 1 )
( PlutusV2.OutputDatum _ ) -> loopInputs xs ( counter + 1 )
7 changes: 6 additions & 1 deletion cogno-contract/src/TagDataType.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module TagDataType
, tSc
, tTag
, tDetail
, tQuoteTxId
, tQuoteIndex
, updateTagData
) where
import qualified PlutusTx
Expand All @@ -52,7 +54,10 @@ data TagData = TagData
-- ^ The tag of the message.
, tDetail :: [PlutusV2.BuiltinByteString]
-- ^ The details of the message.
-- todo add reference txid#
, tQuoteTxId :: PlutusV2.BuiltinByteString
-- ^ The TxId of the quote tag.
, tQuoteIndex :: Integer
-- ^ The Index of the quote tag.
}
PlutusTx.unstableMakeIsData ''TagData

Expand Down
2 changes: 1 addition & 1 deletion cogno-contract/validator.addr
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addr_test1wrcazptka30mxjet6dwrapfkwuau7tk026gh4pvuvnyjyrspychru
addr_test1wz4a7ztrupa4q40k4gzxeh5ld3p25e2w3m8jpvwstrgvdtqq3zat0
2 changes: 1 addition & 1 deletion cogno-contract/validator.bytes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[241, 209, 5, 118, 236, 95, 179, 75, 43, 211, 92, 62, 133, 54, 119, 59, 207, 46, 207, 86, 145, 122, 133, 156, 100, 201, 34, 14]
[171, 223, 9, 99, 224, 123, 80, 85, 246, 170, 4, 108, 222, 159, 108, 66, 170, 101, 78, 142, 207, 32, 177, 208, 88, 208, 198, 172]
2 changes: 1 addition & 1 deletion cogno-contract/validator.hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f1d10576ec5fb34b2bd35c3e8536773bcf2ecf56917a859c64c9220e
abdf0963e07b5055f6aa046cde9f6c42aa654e8ecf20b1d058d0c6ac
Binary file added images/cogno-tag-connection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 21 additions & 6 deletions scripts/balances.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,29 @@ collat_address=$(cat wallets/collat-wallet/payment.addr)
${cli} query protocol-parameters --testnet-magic ${testnet_magic} --out-file tmp/protocol.json
${cli} query tip --testnet-magic ${testnet_magic} | jq

echo -e "\n\nScript Address:" ${script_address}
echo
echo -e "\033[1;35m Script Address:"
echo -e "\n${script_address}\n";
${cli} query utxo --address ${script_address} --testnet-magic ${testnet_magic}
echo -e "\033[0m"

echo -e "\n\nWallet Address:" ${wallet_address}
#
echo
echo -e "\033[1;36m Wallet Address:"
echo -e "\n${wallet_address}\n";
${cli} query utxo --address ${wallet_address} --testnet-magic ${testnet_magic}
echo -e "\033[0m"

echo -e "\n\nReference Address:" ${reference_address}
#
echo
echo -e "\033[1;34m Reference Address:"
echo -e "\n \033[1;34m ${reference_address}\n";
${cli} query utxo --address ${reference_address} --testnet-magic ${testnet_magic}

echo -e "\n\nCollat Address:" ${collat_address}
${cli} query utxo --address ${collat_address} --testnet-magic ${testnet_magic}
echo -e "\033[0m"

#
echo
echo -e "\033[1;33m Collateral Address:"
echo -e "\n${collat_address}\n";
${cli} query utxo --address ${collat_address} --testnet-magic ${testnet_magic}
echo -e "\033[0m"
2 changes: 1 addition & 1 deletion scripts/createReferenceScript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fi
alltxin=""
TXIN=$(jq -r --arg alltxin "" 'keys[] | . + $alltxin + " --tx-in"' tmp/reference_utxo.json)
HEXTXIN=${TXIN::-8}
echo $HEXTXIN
# echo $HEXTXIN
# exit
echo -e "\033[0;36m Building Tx \033[0m"
FEE=$(${cli} transaction build \
Expand Down
2 changes: 1 addition & 1 deletion scripts/createTag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ script_address=$(${cli} address build --payment-script-file ${script_path} --tes
#
issuer_address=$(cat wallets/seller-wallet/payment.addr)

lock_value=2000000
lock_value=10000000
sc_address_out="${script_address} + ${lock_value}"

echo "Script OUTPUT: "${sc_address_out}
Expand Down
16 changes: 4 additions & 12 deletions scripts/data/datum/cogno_datum.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,16 @@
"int": 1
},
{
"bytes": "6120737472696e67"
"bytes": ""
},
{
"list": [
{
"bytes": "a2108b7b1704f9fe12c906096ea1634df8e089c9ccfd651abae4a439"
}
]
"list": []
},
{
"list": [
{
"bytes": "a2108b7b1704f9fe12c906096ea1634df8e089c9ccfd651abae4a439"
}
]
"list": []
},
{
"bytes": "736f6d65206f7468657220737472696e67"
"bytes": ""
}
]
}
Expand Down
Loading