Skip to content

Commit

Permalink
Using bytes32 for id.
Browse files Browse the repository at this point in the history
  • Loading branch information
cfries committed Mar 7, 2024
1 parent dfe3463 commit f79a18a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions solidity/contracts/dvp-impl/PaymentContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract PaymentContract is IDecryptionContract {
string encryptedKeyFailure;
}

mapping(uint256 => TransactionSpec) transactionMap;
mapping(bytes32 => TransactionSpec) transactionMap;

address sellerAddress;
address buyerAddress;
Expand All @@ -26,17 +26,17 @@ contract PaymentContract is IDecryptionContract {
}


function inceptTransfer(uint id, int amount, address from, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external override{
transactionMap[id] = TransactionSpec(from,msg.sender,amount,keyEncryptedSuccess,keyEncryptedFailure);
function inceptTransfer(bytes32 id, int amount, address from, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external override {
transactionMap[id] = TransactionSpec(from, msg.sender, amount, keyEncryptedSuccess, keyEncryptedFailure);
emit PaymentTransferIncepted(msg.sender, id, amount);
}


function transferAndDecrypt(uint id, address from, address to, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external override{
function transferAndDecrypt(bytes32 id, address from, address to, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external override {

}

function cancelAndDecrypt(uint id, address from, address to, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external{
function cancelAndDecrypt(bytes32 id, address from, address to, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external {

}
}
12 changes: 6 additions & 6 deletions solidity/contracts/dvp-impl/interface/IDecryptionContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ interface IDecryptionContract {
* @param id the trade ID.
* @param amount to be transfered.
*/
event PaymentTransferIncepted(address initiator, uint id, int amount);
event PaymentTransferIncepted(address initiator, bytes32 id, int amount);

/**
* @dev Emitted when a the transfer has been performed with a success or failure.
* @param id the trade ID.
* @param encryptedKey The encrypted key associated with the transaction status.
*/
event TransferKeyRequested(uint id, string encryptedKey);
event TransferKeyRequested(bytes32 id, string encryptedKey);

/**
* @dev Emitted when the decrypted key has been obtained.
* @param id the trade ID.
* @param success a boolean indicating the status. True: success. False: failure.
* @param key the descrypted key.
*/
event TransferKeyReleased(uint id, bool success, string key);
event TransferKeyReleased(bytes32 id, bool success, string key);

/*------------------------------------------- FUNCTIONALITY ---------------------------------------------------------------------------------------*/

Expand All @@ -57,7 +57,7 @@ interface IDecryptionContract {
* @param keyEncryptedSuccess Encryption of the key that is emitted upon success.
* @param keyEncryptedFailure Encryption of the key that is emitted upon failure.
*/
function inceptTransfer(uint id, int amount, address from, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;
function inceptTransfer(bytes32 id, int amount, address from, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;

/**
* @notice Called from the sender of the payment to initiate completion of the payment transfer.
Expand All @@ -68,7 +68,7 @@ interface IDecryptionContract {
* @param keyEncryptedSuccess Encryption of the key that is emitted upon success.
* @param keyEncryptedFailure Encryption of the key that is emitted upon failure.
*/
function transferAndDecrypt(uint id, address from, address to, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;
function transferAndDecrypt(bytes32 id, address from, address to, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;

/**
* @notice Called from the payer of the payment to cancel payment transfer.
Expand All @@ -79,5 +79,5 @@ interface IDecryptionContract {
* @param keyEncryptedSuccess Encryption of the key that is emitted upon success.
* @param keyEncryptedFailure Encryption of the key that is emitted upon failure.
*/
function cancelAndDecrypt(uint id, address from, address to, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;
function cancelAndDecrypt(bytes32 id, address from, address to, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;
}
6 changes: 3 additions & 3 deletions solidity/test/DvP.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const abiCoder = new AbiCoder();
console.log("- At first Seller generates a hashed key for the Buyer with solidity keccak256");
await new Promise((resolve) => setTimeout(resolve, secWait));
let hashedKeySeller = ethers.utils.solidityKeccak256(["string"],["keySeller"]);
console.log("- Hashed Key for Buyer is: %s",hashedKeySeller);
console.log("- Hashed Key for Buyer is: %s", hashedKeySeller);
await new Promise((resolve) => setTimeout(resolve, secWait));
console.log("- Seller now calls 'inceptTrade' against the AssetContract providing trade data and hashed key for seller");
await new Promise((resolve) => setTimeout(resolve, secWait));
Expand Down Expand Up @@ -106,11 +106,11 @@ const abiCoder = new AbiCoder();
console.log("3. Seller incepts the DvP-Transfer against the Payment Contract by providing the Buyer's and Seller's encrypted key");
console.log("====================================================================================================");
await new Promise((resolve) => setTimeout(resolve, secWait));
let keyEncryptedBuyer = await EthCrypto.encryptWithPublicKey(dvpOracle.publicKey,"keyFoBuyer");
let keyEncryptedBuyer = await EthCrypto.encryptWithPublicKey(dvpOracle.publicKey, "keyFoBuyer");
let keyEncrypedBuyerAsString = await EthCrypto.cipher.stringify(keyEncryptedBuyer);
console.log("- Seller generates encrypted key for the Buyer by using public key of DvP Oracle: %s",keyEncrypedBuyerAsString);
await new Promise((resolve) => setTimeout(resolve, secWait));
console.log("- Seller retrieves its encrypted key stored in the Asset Contract:",0);
console.log("- Seller retrieves its encrypted key stored in the Asset Contract:", 0);
await new Promise((resolve) => setTimeout(resolve, secWait));
let keyEncrypedSellerAsString = "";
console.log("- Buyer calls 'inceptTransfer' against AssetContract providing the encrypted key for Seller");
Expand Down

0 comments on commit f79a18a

Please sign in to comment.