19
19
import com .bloxbean .cardano .client .transaction .spec .MultiAsset ;
20
20
import com .bloxbean .cardano .client .transaction .spec .Transaction ;
21
21
import com .bloxbean .cardano .client .util .HexUtil ;
22
+ import com .bloxbean .cardano .client .util .Tuple ;
22
23
import lombok .AccessLevel ;
23
24
import lombok .Data ;
24
25
import lombok .Setter ;
25
26
import lombok .SneakyThrows ;
26
27
27
28
import java .util .*;
29
+ import java .util .stream .Collectors ;
28
30
29
31
/**
30
32
* Provides necessary services which are required to build the transaction
@@ -47,11 +49,12 @@ public class TxBuilderContext {
47
49
//Stores utxos used in the transaction.
48
50
//This list is cleared after each build() call.
49
51
private Set <Utxo > utxos = new HashSet <>();
50
- private Map <String , byte []> refScripts = new HashMap <>();
52
+
53
+ @ Setter (AccessLevel .NONE )
54
+ private Map <String , Tuple <PlutusScript , byte []>> refScripts = new HashMap <>();
51
55
52
56
@ Setter (AccessLevel .NONE )
53
57
private boolean mergeOutputs = true ;
54
- private Language referenceInputLanguage = Language .PLUTUS_V2 ;
55
58
56
59
public TxBuilderContext (UtxoSupplier utxoSupplier , ProtocolParamsSupplier protocolParamsSupplier ) {
57
60
this (utxoSupplier , protocolParamsSupplier .getProtocolParams ());
@@ -184,15 +187,32 @@ public void clearUtxos() {
184
187
185
188
@ SneakyThrows
186
189
public void addRefScripts (PlutusScript plutusScript ) {
187
- refScripts .put (HexUtil .encodeHexString (plutusScript .getScriptHash ()), plutusScript .scriptRefBytes ());
190
+ refScripts .put (HexUtil .encodeHexString (plutusScript .getScriptHash ()), new Tuple <>( plutusScript , plutusScript .scriptRefBytes () ));
188
191
}
189
192
190
- public byte [] getRefScript (String scriptHash ) {
191
- return refScripts .get (scriptHash );
193
+ public Optional <byte []> getRefScript (String scriptHash ) {
194
+ var tuple = refScripts .get (scriptHash );
195
+ return tuple != null ? Optional .of (tuple ._2 ) : Optional .empty ();
192
196
}
193
197
194
198
public List <byte []> getRefScripts () {
195
- return new ArrayList <>(refScripts .values ());
199
+ return refScripts .values ().stream ().map (tuple -> tuple ._2 )
200
+ .collect (Collectors .toList ());
201
+ }
202
+
203
+ public List <PlutusScript > getRefPlutusScripts () {
204
+ return refScripts .values ().stream ().map (tuple -> tuple ._1 )
205
+ .collect (Collectors .toList ());
206
+ }
207
+
208
+ public List <Language > getRefScriptLanguages () {
209
+ if (refScripts .size () == 0 )
210
+ return Collections .emptyList ();
211
+
212
+ return refScripts .values ().stream ().map (tuple -> tuple ._1 .getLanguage ())
213
+ .collect (Collectors .toSet ())
214
+ .stream ().sorted (Comparator .comparing (Language ::getKey ))
215
+ .collect (Collectors .toList ());
196
216
}
197
217
198
218
public void clearRefScripts () {
0 commit comments