cardano-client-lib
cardano-client-lib copied to clipboard
scriptDataHash is not generated when transaction contains only plutusDataList
When building the transaction which contains:
- output has datumHash
- witnessSet has plutusDataList
Expected:
- scriptDataHash is generated
Actual:
- scriptDataHash is not generated
Sample valid cbor:
84a6008182582094b5f508897f4e0edd1424e5ecdf9809e4460117cbf387f512cfc813fd6107eb03018283581d7186ae9eebd8b97944a45201e4aec1330a72291af2d071644bba0159591a0632ea005820541c04078a3a2c614b5b3f9b8182a4f42fabb428a6147b78d85f2ed9f26d53278258390124517b26c3373eaeef8bb003d7fdae97a2ae7a6124f1a2f073f78ef453c1fdc3fd349800ddca096ce3431f31109d12fe6f72b31c4027238c1a0282f1b9021a0002c405031a05e36f48081a05e361380b5820f57b09d892bc52cbaead361e2e6b5701b6a751757bde9b9387ecfe902ef16678a10481d8799fd8799fd8799fd8799f581c24517b26c3373eaeef8bb003d7fdae97a2ae7a6124f1a2f073f78ef4ffd8799fd8799fd8799f581c53c1fdc3fd349800ddca096ce3431f31109d12fe6f72b31c4027238cffffffff581c24517b26c3373eaeef8bb003d7fdae97a2ae7a6124f1a2f073f78ef41b000001899244bae0d8799fd8799f4040ffd8799f581cf66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b698804469555344ffffffd8799fd879801a01cacaeafffff5f6
Cbor preview:
[
{
0: [
[
h'94b5f508897f4e0edd1424e5ecdf9809e4460117cbf387f512cfc813fd6107eb',
3,
],
],
1: [
[
h'7186ae9eebd8b97944a45201e4aec1330a72291af2d071644bba015959',
104000000_2,
h'541c04078a3a2c614b5b3f9b8182a4f42fabb428a6147b78d85f2ed9f26d5327',
],
[
h'0124517b26c3373eaeef8bb003d7fdae97a2ae7a6124f1a2f073f78ef453c1fdc3fd349800ddca096ce3431f31109d12fe6f72b31c4027238c',
42135993_2,
],
],
2: 181253_2,
3: 98791240_2,
8: 98787640_2,
11: h'f57b09d892bc52cbaead361e2e6b5701b6a751757bde9b9387ecfe902ef16678',
},
{
4: [
121_0([_
121_0([_
121_0([_
121_0([_
h'24517b26c3373eaeef8bb003d7fdae97a2ae7a6124f1a2f073f78ef4',
]),
121_0([_
121_0([_
121_0([_
h'53c1fdc3fd349800ddca096ce3431f31109d12fe6f72b31c4027238c',
]),
]),
]),
]),
h'24517b26c3373eaeef8bb003d7fdae97a2ae7a6124f1a2f073f78ef4',
1690376125152_3,
121_0([_
121_0([_ h'', h'']),
121_0([_
h'f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b69880',
h'69555344',
]),
]),
]),
121_0([_ 121_0([]), 30067434_2]),
]),
],
},
true,
null,
]
This cbor is created by Indigo Swap
In ScriptDataHashCalculator
the lib is checking this condition:
boolean containsPlutusScript = false;
//check if plutusscript exists
if ((transaction.getWitnessSet().getPlutusV1Scripts() != null
&& transaction.getWitnessSet().getPlutusV1Scripts().size() > 0)
|| (transaction.getWitnessSet().getPlutusV2Scripts() != null
&& transaction.getWitnessSet().getPlutusV2Scripts().size() > 0)
|| (transaction.getWitnessSet().getRedeemers() != null
&& transaction.getWitnessSet().getRedeemers().size() > 0)
) {
containsPlutusScript = true;
}
Thanks @iTanChi
The library expects at least one redeemer (a redeemer with unit data is also ok) to determine if it is a script transaction. Since a null redeemer is also allowed, we need to address this by adding an additional check for the datum list.
Is this a Plutus V1 or V2 transaction? I do not see any reference inputs or Plutus script in the witness set.
As a workaround for now :
- Try to add the Plutus script to the witness set in order to generate the script data hash. You can remove it prior to transaction signing.
- Otherwise, create a copy of
ScriptDataHashCalculator
class with datum list check and usecalculateScriptDataHash()
function in TxBuilder before balanceTx.
@satran004 sorry for late response. That cbor was from dex when I created a swap request. I'm not sure it's a V1 or V2 transaction because I try using your lib to recreate the transaction but could not because of missing script data hash