Skip to content

Commit 3a335e8

Browse files
Merge pull request #207 from dhinakaran2705/main
Besu asset exchange now works with any 32 byte secret preimage
2 parents 4ba0e2d + 4649b4d commit 3a335e8

File tree

16 files changed

+45
-39
lines changed

16 files changed

+45
-39
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name=Interop Protos
22
group=com.weaver
3-
version=1.2.4-alpha.8
3+
version=1.2.4-alpha.9
44
kotlin.incremental=false

core/network/besu/contracts/interop/manageAsset.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ contract InteroperationBaseClassERC20 {
4040
address indexed receiver,
4141
bytes32 indexed lockContractId,
4242
bytes32 hashLock,
43-
bytes32 preimage
43+
string preimage
4444
);
4545

4646
event Unlock(
@@ -109,7 +109,7 @@ contract InteroperationBaseClassERC20 {
109109

110110

111111
// The receiver claims the ownership of an asset locked for them once they obtain the preimage of the hashlock
112-
function claimFungibleAsset(bytes32 lockContractId, bytes32 preimage)
112+
function claimFungibleAsset(bytes32 lockContractId, string memory preimage)
113113
external
114114
returns (bool)
115115
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name=Interoperability CorDapp
22
group=com.weaver.corda.app.interop
3-
version=1.2.4-alpha.8
3+
version=1.2.4-alpha.9
44
kotlin.incremental=false

docs/docs/external/getting-started/test-network/overview.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ title: Component Overview
1212
Weaver offers a basic test network launching capability, both to demonstrate interoperation modes and to serve as a testbed for development and prototyping. Different modes (or scenarios) require different sets of components, but collectively you will need to run the following:
1313

1414
- [Fabric testnet](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/tests/network-setups/fabric/dev) - A pair of basic Fabric networks for testing interop flows
15-
- [Corda testnet](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/tests/network-setups/corda) - A basic Corda network for testing interop flows
15+
- [Corda testnet](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/tests/network-setups/corda) - A pair of basic Corda networks for testing interop flows
16+
- [Besu testnet](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/tests/network-setups/besu) - A pair of basic Besu networks for testing interop flows
1617
- [Relay](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/core/relay) - The server module and protocol for cross-DLT interoperability. An instance of this is needed for every Fabric and Corda network
1718
- [Fabric driver](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/core/drivers/fabric-driver) - Driver used by the Fabric networks relay to communicate with the Fabric testnet
1819
- [Corda driver](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/core/drivers/corda-driver) - Driver used by the Corda networks relay to communicate with the Corda testnet
20+
- [Fabric Interop chaincode](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/core/network/fabric-interop-cc) - The Fabric interoperability contracts handle the dual process of servicing requests for views from external networks, and verifying requested views for integrity
1921
- [Corda interop app](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/core/network/corda-interop-app) CorDapp used to handle interop duties between the relay and the application
20-
- [Corda client app](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/samples/corda/corda-simple-application) - CorDapp and client used to trigger interop flows initiated from the Corda side and to manage Corda state
22+
- [Besu interop contract](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/core/network/besu/contracts/interop) Solidity smart contract(s) used to handle interop duties for a Besu network
2123
- [Fabric client](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/samples/fabric/fabric-cli) - Fabric client used to trigger interop flows initiated from the Fabric side and to manage Fabric state
22-
- [Fabric Interop chaincode](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/core/network/fabric-interop-cc) - The Fabric interoperability contracts handle the dual process of servicing requests for views from external networks, and verifying requested views for integrity
24+
- [Corda client app](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/samples/corda/corda-simple-application) - CorDapp and client used to trigger interop flows initiated from the Corda side and to manage Corda state
25+
- [Besu sample application](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/samples/besu/simpleasset) - A sample application for asset exchange across two besu networks using HTLC
26+
- [Besu client app](https://github.com/hyperledger-labs/weaver-dlt-interoperability/tree/master/samples/besu/besu-cli) - Besu client used to interact with the contracts deployed on the Besu testnet
2327

2428
You can launch these components in one of several different ways:
2529
* **Setup with Locally Built Weaver Components**:

samples/besu/besu-cli/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2
4444
A random preimage and its corresponding hash will be generated and the preimage will be output, along with the lockContractID, to be used during Claim.
4545
- asset claim: Claim assets (fungible assets for now)
4646
```
47-
besu-cli asset claim --network=network1 --lock_contract_id=lockContractID --recipient_account=2 --preimage_base64=preimage
47+
besu-cli asset claim --network=network1 --lock_contract_id=lockContractID --recipient_account=2 --preimage=preimage
4848
```
4949
- asset unlock: Unlock and reclaim assets after timeout (fungible assets for now)
5050
```

samples/besu/besu-cli/src/commands/asset/claim.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const command: GluegunCommand = {
1616
commandHelp(
1717
print,
1818
toolbox,
19-
`besu-cli asset claim --network=network1 --lock_contract_id=lockContractID --recipient_account=2 --preimage_base64=preimage`,
20-
'besu-cli asset claim --network=<network1|network2> --lock_contract_id=<lockContractID> --recipient_account=<2|1> --preimage_base64=<preimage>',
19+
`besu-cli asset claim --network=network1 --lock_contract_id=lockContractID --recipient_account=2 --preimage=preimage`,
20+
'besu-cli asset claim --network=<network1|network2> --lock_contract_id=<lockContractID> --recipient_account=<2|1> --preimage=<preimage>',
2121
[
2222
{
2323
name: '--network',
@@ -35,9 +35,9 @@ const command: GluegunCommand = {
3535
'The index of the account of the recipient of the asset from the list obtained through web3.eth.getAccounts(). For example, we can set Alice as accounts[1] and hence value of this parameter for Alice can be 1.'
3636
},
3737
{
38-
name: '--preimage_base64',
38+
name: '--preimage',
3939
description:
40-
'The preimage of hash with which the asset was locked with. Input format supported: base64.'
40+
'The preimage of hash with which the asset was locked with.'
4141
}
4242
],
4343
command,
@@ -76,26 +76,26 @@ const command: GluegunCommand = {
7676
print.error('Lock contract ID not provided.')
7777
return
7878
}
79-
const lockContractId = options.lock_contract_id
80-
if(!options.preimage_base64){
79+
const lockContractId = '0x' + options.lock_contract_id
80+
if(!options.preimage){
8181
print.error('Preimage not provided.')
8282
return
8383
}
84-
const preimage_base64 = options.preimage_base64
85-
const preimage = Buffer.from(preimage_base64, 'base64')
86-
console.log('Length of preimage:', preimage.length)
8784

8885
console.log('Parameters')
8986
console.log('networkConfig', networkConfig)
9087
console.log('Receiver', recipient)
9188
console.log('Lock Contract ID', lockContractId)
92-
console.log('Preimage', preimage)
89+
console.log('Preimage', options.preimage)
90+
91+
const preimage_bytes32 = web3N.utils.utf8ToHex(options.preimage)
92+
console.log('Preimage bytes32:', preimage_bytes32)
9393

9494
// Balance of the recipient before claiming
9595
var recipientBalance = await tokenContract.balanceOf(recipient)
9696
console.log(`Account balance of the recipient in Network ${options.network} before claiming: ${recipientBalance.toString()}`)
9797

98-
await interopContract.claimFungibleAsset(lockContractId, preimage, {
98+
await interopContract.claimFungibleAsset(lockContractId, options.preimage, {
9999
from: recipient,
100100
}).catch((error) => {
101101
console.log("claimFungibleAsset threw an error:", error);

samples/besu/besu-cli/src/commands/asset/is-locked.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,24 @@ const command: GluegunCommand = {
4141
print.error('Lock contract ID not provided.')
4242
return
4343
}
44+
const lockContractId = '0x' + options.lock_contract_id
4445

4546
console.log('Parameters')
4647
console.log('networkConfig', networkConfig)
47-
console.log('Lock Contract ID', options.lock_contract_id)
48+
console.log('Lock Contract ID', lockContractId)
4849

4950
const provider = new Web3.providers.HttpProvider('http://'+networkConfig.networkHost+':'+networkConfig.networkPort)
5051
const web3N = new Web3(provider)
5152
const interopContract = await getContractInstance(provider, networkConfig.interopContract)
5253
const accounts = await web3N.eth.getAccounts()
5354
var sender = accounts[networkConfig.senderAccountIndex]
5455

55-
var isLocked = await interopContract.isFungibleAssetLocked(options.lock_contract_id, {
56+
var isLocked = await interopContract.isFungibleAssetLocked(lockContractId, {
5657
from: sender
5758
}).catch(function () {
5859
console.log("isFungibleAssetLocked threw an error");
5960
})
60-
console.log(`Is there an asset locked in ${options.lock_contract_id} in Network ${options.network}: ${isLocked}`) //Todo: Debug. isLocked is not printing correctly.
61+
console.log(`Is there an asset locked in ${lockContractId} in Network ${options.network}: ${isLocked}`) //Todo: Debug. isLocked is not printing correctly.
6162
}
6263
}
6364

samples/besu/besu-cli/src/commands/asset/lock.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const command: GluegunCommand = {
1818
print,
1919
toolbox,
2020
`besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --amount=5 --timeout=1000`,
21-
'besu-cli asset lock --network=<network1|network2> --sender_account=<1|2> --recipient_account=<2|1> --amount=<lock-amount> --timeout=<lock-duration-seconds> --hash=<hashLock-optional-parameter>',
21+
'besu-cli asset lock --network=<network1|network2> --sender_account=<1|2> --recipient_account=<2|1> --amount=<lock-amount> --timeout=<lock-duration-seconds> --hash_base64=<hashLock-optional-parameter>',
2222
[
2323
{
2424
name: '--network',
@@ -105,15 +105,16 @@ const command: GluegunCommand = {
105105
var hash
106106
var preimage
107107
var hash_base64
108-
var preimage_base64
108+
var preimage_bytes
109109
if(options.hash_base64){
110110
hash_base64 = options.hash_base64
111111
}
112112
else{
113113
// Generate a hash pair if not provided as an input parameter
114-
preimage_base64 = crypto.randomBytes(32).toString('base64')
115-
preimage = Buffer.from(preimage_base64, 'base64')
114+
preimage = crypto.randomBytes(22).toString('base64')
116115
hash_base64 = crypto.createHash('sha256').update(preimage).digest('base64')
116+
preimage_bytes = Buffer.from(preimage)
117+
console.log('Length of preimage byte array', preimage_bytes.length)
117118
}
118119
hash = Buffer.from(hash_base64, 'base64')
119120

@@ -124,7 +125,7 @@ const command: GluegunCommand = {
124125
console.log('Amount', options.amount)
125126
console.log('Timeout', timeLock)
126127
console.log('Hash (base64): ', hash_base64)
127-
console.log('Preimage (base64): ', preimage_base64)
128+
console.log('Preimage: ', preimage)
128129

129130
// Balances of sender and receiver before locking
130131
console.log(`Account balances before locking`)
@@ -150,7 +151,7 @@ const command: GluegunCommand = {
150151
console.log("lockFungibleAsset threw an error");
151152
})
152153
const lockContractId = lockTx.logs[0].args.lockContractId
153-
console.log(`Lock contract ID: ${lockContractId}`)
154+
console.log(`Lock contract ID: ${lockContractId.toString().substring(2)}`)
154155

155156
// Balances of sender and receiver after locking
156157
console.log(`Account balances after locking`)

samples/besu/besu-cli/src/commands/asset/unlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const command: GluegunCommand = {
7171
print.error('Lock contract ID not provided.')
7272
return
7373
}
74-
const lockContractId = options.lock_contract_id
74+
const lockContractId = '0x' + options.lock_contract_id
7575

7676
console.log('Paramters')
7777
console.log('networkConfig', networkConfig)

samples/corda/corda-simple-application/constants.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ log4jVersion =2.16.0
99
platformVersion=10
1010
slf4jVersion=1.7.25
1111
nettyVersion=4.1.22.Final
12-
weaverVersion=1.2.4-alpha.8
12+
weaverVersion=1.2.4-alpha.9

0 commit comments

Comments
 (0)