Skip to content

Commit 6fef812

Browse files
authored
Merge pull request #357 from Emurgo/plutus-datum-json-support
cardano-cli Plutus Datum JSON format support
2 parents 04c4e7a + 39736ac commit 6fef812

File tree

3 files changed

+432
-2
lines changed

3 files changed

+432
-2
lines changed

rust/pkg/cardano_serialization_lib.js.flow

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,26 @@ declare export function decrypt_with_password(
230230
data: string
231231
): string;
232232

233+
/**
234+
* @param {string} json
235+
* @param {number} schema
236+
* @returns {PlutusData}
237+
*/
238+
declare export function encode_json_str_to_plutus_datum(
239+
json: string,
240+
schema: number
241+
): PlutusData;
242+
243+
/**
244+
* @param {PlutusData} datum
245+
* @param {number} schema
246+
* @returns {string}
247+
*/
248+
declare export function decode_plutus_datum_to_json_str(
249+
datum: PlutusData,
250+
schema: number
251+
): string;
252+
233253
/**
234254
*/
235255

@@ -369,6 +389,31 @@ declare export var RedeemerTagKind: {|
369389
+Reward: 3, // 3
370390
|};
371391

392+
/**
393+
* JSON <-> PlutusData conversion schemas.
394+
* Follows ScriptDataJsonSchema in cardano-cli defined at:
395+
* https://github.com/input-output-hk/cardano-node/blob/master/cardano-api/src/Cardano/Api/ScriptData.hs#L254
396+
*
397+
* All methods here have the following restrictions due to limitations on dependencies:
398+
* * JSON numbers above u64::MAX (positive) or below i64::MIN (negative) will throw errors
399+
* * Hex strings for bytes don't accept odd-length (half-byte) strings.
400+
* cardano-cli seems to support these however but it seems to be different than just 0-padding
401+
* on either side when tested so proceed with caution
402+
*/
403+
404+
declare export var PlutusDatumSchema: {|
405+
+BasicConversions: 0, // 0
406+
+DetailedSchema: 1, // 1
407+
|};
408+
409+
/**
410+
*/
411+
412+
declare export var StakeCredKind: {|
413+
+Key: 0, // 0
414+
+Script: 1, // 1
415+
|};
416+
372417
/**
373418
*/
374419

@@ -694,6 +739,11 @@ declare export class BigInt {
694739
*/
695740
as_u64(): BigNum | void;
696741

742+
/**
743+
* @returns {Int | void}
744+
*/
745+
as_int(): Int | void;
746+
697747
/**
698748
* @param {string} text
699749
* @returns {BigInt}

0 commit comments

Comments
 (0)