Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSL 11.4.0 #100

Merged
merged 2 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5095,6 +5095,14 @@ public final void plutusDataNewEmptyConstrPlutusData(String alternative, Promise
.pour(promise);
}

@ReactMethod
public final void plutusDataNewSingleValueConstrPlutusData(String alternative, String plutusData, Promise promise) {
Native.I
.plutusDataNewSingleValueConstrPlutusData(new RPtr(alternative), new RPtr(plutusData))
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void plutusDataNewMap(String map, Promise promise) {
Native.I
Expand Down Expand Up @@ -5189,6 +5197,14 @@ public final void plutusDataFromJson(String json, Double schema, Promise promise
.pour(promise);
}

@ReactMethod
public final void plutusDataFromAddress(String address, Promise promise) {
Native.I
.plutusDataFromAddress(new RPtr(address))
.map(RPtr::toJs)
.pour(promise);
}


@ReactMethod
public final void plutusListToBytes(String self, Promise promise) {
Expand Down Expand Up @@ -10339,6 +10355,13 @@ public final void transactionOutputNew(String address, String amount, Promise pr
.pour(promise);
}

@ReactMethod
public final void transactionOutputSerializationFormat(String self, Promise promise) {
Native.I
.transactionOutputSerializationFormat(new RPtr(self))
.pour(promise);
}


@ReactMethod
public final void transactionOutputAmountBuilderWithValue(String self, String amount, Promise promise) {
Expand Down
3 changes: 3 additions & 0 deletions android/src/main/java/io/emurgo/rnhaskellshelley/Native.java
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ private Native() { }
public final native Result<RPtr> plutusDataFromHex(String hexStr);
public final native Result<RPtr> plutusDataNewConstrPlutusData(RPtr constrPlutusData);
public final native Result<RPtr> plutusDataNewEmptyConstrPlutusData(RPtr alternative);
public final native Result<RPtr> plutusDataNewSingleValueConstrPlutusData(RPtr alternative, RPtr plutusData);
public final native Result<RPtr> plutusDataNewMap(RPtr map);
public final native Result<RPtr> plutusDataNewList(RPtr list);
public final native Result<RPtr> plutusDataNewInteger(RPtr integer);
Expand All @@ -742,6 +743,7 @@ private Native() { }
public final native Result<byte[]> plutusDataAsBytes(RPtr self);
public final native Result<String> plutusDataToJson(RPtr self, int schema);
public final native Result<RPtr> plutusDataFromJson(String json, int schema);
public final native Result<RPtr> plutusDataFromAddress(RPtr address);

public final native Result<byte[]> plutusListToBytes(RPtr self);
public final native Result<RPtr> plutusListFromBytes(byte[] bytes);
Expand Down Expand Up @@ -1466,6 +1468,7 @@ private Native() { }
public final native Result<Boolean> transactionOutputHasDataHash(RPtr self);
public final native Result<Boolean> transactionOutputHasScriptRef(RPtr self);
public final native Result<RPtr> transactionOutputNew(RPtr address, RPtr amount);
public final native Result<Integer> transactionOutputSerializationFormat(RPtr self);

public final native Result<RPtr> transactionOutputAmountBuilderWithValue(RPtr self, RPtr amount);
public final native Result<RPtr> transactionOutputAmountBuilderWithCoin(RPtr self, RPtr coin);
Expand Down
5 changes: 4 additions & 1 deletion codegen/android_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def get_arg_android_rust_result_cast(arg):
else:
cast = "result.into_jlong().jobject(&env)"
elif arg.is_enum:
cast = "(result.to_i32() as jint).jobject(&env)"
if arg.is_optional:
cast = "result.map(|x| x.to_i32() as jint).jobject(&env)"
else:
cast = "(result.to_i32() as jint).jobject(&env)"
else:
cast = "result.rptr().jptr(&env)"
return cast
Expand Down
2 changes: 1 addition & 1 deletion codegen/cardano_serialization_lib.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion codegen/js_index_d_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def map_js_type(arg):
else:
return "number"
elif arg.is_enum:
return arg.struct_orig_name
if optional:
return f"Optional<{arg.struct_orig_name}>"
else:
return arg.struct_orig_name
else:
if optional:
return "Optional<" + arg.struct_name + ">"
Expand Down
24 changes: 24 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3840,6 +3840,13 @@ export class PlutusData extends Ptr {
*/
static new_empty_constr_plutus_data: (alternative: BigNum) => Promise<PlutusData>;

/**
* @param {BigNum} alternative
* @param {PlutusData} plutus_data
* @returns {Promise<PlutusData>}
*/
static new_single_value_constr_plutus_data: (alternative: BigNum, plutus_data: PlutusData) => Promise<PlutusData>;

/**
* @param {PlutusMap} map
* @returns {Promise<PlutusData>}
Expand Down Expand Up @@ -3907,6 +3914,12 @@ export class PlutusData extends Ptr {
*/
static from_json: (json: string, schema: PlutusDatumSchema) => Promise<Optional<PlutusData>>;

/**
* @param {Address} address
* @returns {Promise<Optional<PlutusData>>}
*/
static from_address: (address: Address) => Promise<Optional<PlutusData>>;

}


Expand Down Expand Up @@ -7706,6 +7719,11 @@ export class TransactionOutput extends Ptr {
*/
static new: (address: Address, amount: Value) => Promise<TransactionOutput>;

/**
* @returns {Promise<Optional<CborContainerType>>}
*/
serialization_format: () => Promise<Optional<CborContainerType>>;

}


Expand Down Expand Up @@ -9054,6 +9072,12 @@ export const min_fee: (tx: Transaction, linear_fee: LinearFee) => Promise<Option
*/
export const min_script_fee: (tx: Transaction, ex_unit_prices: ExUnitPrices) => Promise<Optional<BigNum>>;

export enum CborContainerType {
Array = 0,
Map = 1,
}


export enum CertificateKind {
StakeRegistration = 0,
StakeDeregistration = 1,
Expand Down
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3718,6 +3718,13 @@ export class PlutusData extends Ptr {
return Ptr._wrap(ret, PlutusData);
}

static async new_single_value_constr_plutus_data(alternative, plutus_data) {
const alternativePtr = Ptr._assertClass(alternative, BigNum);
const plutus_dataPtr = Ptr._assertClass(plutus_data, PlutusData);
const ret = await HaskellShelley.plutusDataNewSingleValueConstrPlutusData(alternativePtr, plutus_dataPtr);
return Ptr._wrap(ret, PlutusData);
}

static async new_map(map) {
const mapPtr = Ptr._assertClass(map, PlutusMap);
const ret = await HaskellShelley.plutusDataNewMap(mapPtr);
Expand Down Expand Up @@ -3781,6 +3788,12 @@ export class PlutusData extends Ptr {
return Ptr._wrap(ret, PlutusData);
}

static async from_address(address) {
const addressPtr = Ptr._assertClass(address, Address);
const ret = await HaskellShelley.plutusDataFromAddress(addressPtr);
return Ptr._wrap(ret, PlutusData);
}

}


Expand Down Expand Up @@ -7518,6 +7531,11 @@ export class TransactionOutput extends Ptr {
return Ptr._wrap(ret, TransactionOutput);
}

async serialization_format() {
const ret = await HaskellShelley.transactionOutputSerializationFormat(this.ptr);
return ret;
}

}


Expand Down Expand Up @@ -8843,6 +8861,12 @@ export const min_script_fee = async (tx, ex_unit_prices) => {
};


export const CborContainerType = Object.freeze({
Array: 0,
Map: 1,
});


export const CertificateKind = Object.freeze({
StakeRegistration: 0,
StakeDeregistration: 1,
Expand Down
34 changes: 34 additions & 0 deletions ios/HaskellShelley.m
Original file line number Diff line number Diff line change
Expand Up @@ -7251,6 +7251,18 @@ + (void)initialize
}] exec:alternativePtr andResolve:resolve orReject:reject];
}

RCT_EXPORT_METHOD(plutusDataNewSingleValueConstrPlutusData:(nonnull NSString *)alternativePtr withPlutusData:(nonnull NSString *)plutusDataPtr withResolve:(RCTPromiseResolveBlock)resolve andReject:(RCTPromiseRejectBlock)reject)
{
[[CSafeOperation new:^NSString*(NSArray* params, CharPtr* error) {
RPtr result;
RPtr alternative = [[params objectAtIndex:0] rPtr];
RPtr plutusData = [[params objectAtIndex:1] rPtr];
return plutus_data_new_single_value_constr_plutus_data(alternative, plutusData, &result, error)
? [NSString stringFromPtr:result]
: nil;
}] exec:@[alternativePtr, plutusDataPtr] andResolve:resolve orReject:reject];
}

RCT_EXPORT_METHOD(plutusDataNewMap:(nonnull NSString *)mapPtr withResolve:(RCTPromiseResolveBlock)resolve andReject:(RCTPromiseRejectBlock)reject)
{
[[CSafeOperation new:^NSString*(NSString* mapPtr, CharPtr* error) {
Expand Down Expand Up @@ -7385,6 +7397,17 @@ + (void)initialize
}] exec:@[jsonVal, schemaVal] andResolve:resolve orReject:reject];
}

RCT_EXPORT_METHOD(plutusDataFromAddress:(nonnull NSString *)addressPtr withResolve:(RCTPromiseResolveBlock)resolve andReject:(RCTPromiseRejectBlock)reject)
{
[[CSafeOperation new:^NSString*(NSString* addressPtr, CharPtr* error) {
RPtr result;
RPtr address = [addressPtr rPtr];
return plutus_data_from_address(address, &result, error)
? [NSString stringFromPtr:result]
: nil;
}] exec:addressPtr andResolve:resolve orReject:reject];
}


RCT_EXPORT_METHOD(plutusListToBytes:(nonnull NSString *)selfPtr withResolve:(RCTPromiseResolveBlock)resolve andReject:(RCTPromiseRejectBlock)reject)
{
Expand Down Expand Up @@ -14724,6 +14747,17 @@ + (void)initialize
}] exec:@[addressPtr, amountPtr] andResolve:resolve orReject:reject];
}

RCT_EXPORT_METHOD(transactionOutputSerializationFormat:(nonnull NSString *)selfPtr withResolve:(RCTPromiseResolveBlock)resolve andReject:(RCTPromiseRejectBlock)reject)
{
[[CSafeOperation new:^NSNumber*(NSString* selfPtr, CharPtr* error) {
int32_t result;
RPtr self = [selfPtr rPtr];
return transaction_output_serialization_format(self, &result, error)
? [NSNumber numberWithLong:result]
: nil;
}] exec:selfPtr andResolve:resolve orReject:reject];
}


RCT_EXPORT_METHOD(transactionOutputAmountBuilderWithValue:(nonnull NSString *)selfPtr withAmount:(nonnull NSString *)amountPtr withResolve:(RCTPromiseResolveBlock)resolve andReject:(RCTPromiseRejectBlock)reject)
{
Expand Down
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cbindgen = "=0.14.1"
cryptoxide = { git = "https://github.com/emurgo/cryptoxide", tag="0.4.4"}

[dependencies]
cardano-serialization-lib = "11.3.0"
cardano-serialization-lib = "11.4.0"
byteorder = "1.4.3"
base64 = "0.20.0"
# tag = "2.3.1"
Expand Down
42 changes: 42 additions & 0 deletions rust/src/android/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ use cardano_serialization_lib::plutus::Strings;
use cardano_serialization_lib::plutus::decode_plutus_datum_to_json_str;
use cardano_serialization_lib::plutus::encode_json_str_to_plutus_datum;
use cardano_serialization_lib::protocol_types::fixed_tx::FixedTransaction;
use cardano_serialization_lib::ser_info::types::CborContainerType;
use cardano_serialization_lib::tx_builder::CoinSelectionStrategyCIP2;
use cardano_serialization_lib::tx_builder::TransactionBuilder;
use cardano_serialization_lib::tx_builder::TransactionBuilderConfig;
Expand Down Expand Up @@ -8657,6 +8658,21 @@ pub unsafe extern "C" fn Java_io_emurgo_rnhaskellshelley_Native_plutusDataNewEmp
}


#[allow(non_snake_case)]
#[no_mangle]
pub unsafe extern "C" fn Java_io_emurgo_rnhaskellshelley_Native_plutusDataNewSingleValueConstrPlutusData(env: JNIEnv, _: JObject, alternative_ptr: JRPtr, plutus_data_ptr: JRPtr) -> jobject {
handle_exception_result(|| {
let alternative_jrptr = alternative_ptr.rptr(&env)?;
let alternative = alternative_jrptr.typed_ref::<BigNum>()?;
let plutus_data_jrptr = plutus_data_ptr.rptr(&env)?;
let plutus_data = plutus_data_jrptr.typed_ref::<PlutusData>()?;
let result = PlutusData::new_single_value_constr_plutus_data(alternative, plutus_data);
result.rptr().jptr(&env)
})
.jresult(&env)
}


#[allow(non_snake_case)]
#[no_mangle]
pub unsafe extern "C" fn Java_io_emurgo_rnhaskellshelley_Native_plutusDataNewMap(env: JNIEnv, _: JObject, map_ptr: JRPtr) -> jobject {
Expand Down Expand Up @@ -8816,6 +8832,19 @@ pub unsafe extern "C" fn Java_io_emurgo_rnhaskellshelley_Native_plutusDataFromJs
}


#[allow(non_snake_case)]
#[no_mangle]
pub unsafe extern "C" fn Java_io_emurgo_rnhaskellshelley_Native_plutusDataFromAddress(env: JNIEnv, _: JObject, address_ptr: JRPtr) -> jobject {
handle_exception_result(|| {
let address_jrptr = address_ptr.rptr(&env)?;
let address = address_jrptr.typed_ref::<Address>()?;
let result = PlutusData::from_address(address).into_result()?;
result.rptr().jptr(&env)
})
.jresult(&env)
}



#[allow(non_snake_case)]
#[no_mangle]
Expand Down Expand Up @@ -17642,6 +17671,19 @@ pub unsafe extern "C" fn Java_io_emurgo_rnhaskellshelley_Native_transactionOutpu
}


#[allow(non_snake_case)]
#[no_mangle]
pub unsafe extern "C" fn Java_io_emurgo_rnhaskellshelley_Native_transactionOutputSerializationFormat(env: JNIEnv, _: JObject, self_ptr: JRPtr) -> jobject {
handle_exception_result(|| {
let self_jrptr = self_ptr.rptr(&env)?;
let self_rptr = self_jrptr.typed_ref::<TransactionOutput>()?;
let result = self_rptr.serialization_format();
result.map(|x| x.to_i32() as jint).jobject(&env)
})
.jresult(&env)
}



#[allow(non_snake_case)]
#[no_mangle]
Expand Down
20 changes: 20 additions & 0 deletions rust/src/enum_maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use cardano_serialization_lib::plutus::LanguageKind;
use cardano_serialization_lib::plutus::PlutusDataKind;
use cardano_serialization_lib::plutus::PlutusDatumSchema;
use cardano_serialization_lib::plutus::RedeemerTagKind;
use cardano_serialization_lib::ser_info::types::CborContainerType;
use cardano_serialization_lib::tx_builder::CoinSelectionStrategyCIP2;
use cardano_serialization_lib::utils::ScriptSchema;

Expand All @@ -24,6 +25,25 @@ pub trait ToPrimitive {
pub trait ToEnum<T> {
fn to_enum(&self) -> Result<T>;
}
impl ToPrimitive for CborContainerType {
fn to_i32(&self) -> i32 {
match self {
CborContainerType::Array => 0,
CborContainerType::Map => 1,
}
}
}

impl ToEnum<CborContainerType> for i32 {
fn to_enum(&self) -> Result<CborContainerType> {
match self {
0 => Ok(CborContainerType::Array),
1 => Ok(CborContainerType::Map),
_ => Err("Invalid value for CborContainerType".into()),
}
}
}

impl ToPrimitive for CertificateKind {
fn to_i32(&self) -> i32 {
match self {
Expand Down
Loading