diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b42bff..6619daf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Changelog ========= ========= +#### Version 3.3.17 +* Add param `resolve_last` to call smart contract public method from specific address + #### Version 3.3.16 * Update `Transaction` model from Blockchain structure diff --git a/lib/src/model/smart_contracts/sc_call_function_params.dart b/lib/src/model/smart_contracts/sc_call_function_params.dart new file mode 100644 index 0000000..ffe96c0 --- /dev/null +++ b/lib/src/model/smart_contracts/sc_call_function_params.dart @@ -0,0 +1,19 @@ +/// SPDX-License-Identifier: AGPL-3.0-or-later +// ignore_for_file: invalid_annotation_target +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'sc_call_function_params.freezed.dart'; +part 'sc_call_function_params.g.dart'; + +@freezed +class SCCallFunctionParams with _$SCCallFunctionParams { + factory SCCallFunctionParams({ + required String contract, + required String function, + required List args, + @Default(true) @JsonKey(name: 'resolve_last') bool resolveLast, + }) = _SCCallFunctionParams; + + factory SCCallFunctionParams.fromJson(Map json) => + _$SCCallFunctionParamsFromJson(json); +} diff --git a/lib/src/model/smart_contracts/sc_call_function_params.freezed.dart b/lib/src/model/smart_contracts/sc_call_function_params.freezed.dart new file mode 100644 index 0000000..7b911af --- /dev/null +++ b/lib/src/model/smart_contracts/sc_call_function_params.freezed.dart @@ -0,0 +1,233 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'sc_call_function_params.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +SCCallFunctionParams _$SCCallFunctionParamsFromJson(Map json) { + return _SCCallFunctionParams.fromJson(json); +} + +/// @nodoc +mixin _$SCCallFunctionParams { + String get contract => throw _privateConstructorUsedError; + String get function => throw _privateConstructorUsedError; + List get args => throw _privateConstructorUsedError; + @JsonKey(name: 'resolve_last') + bool get resolveLast => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SCCallFunctionParamsCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SCCallFunctionParamsCopyWith<$Res> { + factory $SCCallFunctionParamsCopyWith(SCCallFunctionParams value, + $Res Function(SCCallFunctionParams) then) = + _$SCCallFunctionParamsCopyWithImpl<$Res, SCCallFunctionParams>; + @useResult + $Res call( + {String contract, + String function, + List args, + @JsonKey(name: 'resolve_last') bool resolveLast}); +} + +/// @nodoc +class _$SCCallFunctionParamsCopyWithImpl<$Res, + $Val extends SCCallFunctionParams> + implements $SCCallFunctionParamsCopyWith<$Res> { + _$SCCallFunctionParamsCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? contract = null, + Object? function = null, + Object? args = null, + Object? resolveLast = null, + }) { + return _then(_value.copyWith( + contract: null == contract + ? _value.contract + : contract // ignore: cast_nullable_to_non_nullable + as String, + function: null == function + ? _value.function + : function // ignore: cast_nullable_to_non_nullable + as String, + args: null == args + ? _value.args + : args // ignore: cast_nullable_to_non_nullable + as List, + resolveLast: null == resolveLast + ? _value.resolveLast + : resolveLast // ignore: cast_nullable_to_non_nullable + as bool, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SCCallFunctionParamsImplCopyWith<$Res> + implements $SCCallFunctionParamsCopyWith<$Res> { + factory _$$SCCallFunctionParamsImplCopyWith(_$SCCallFunctionParamsImpl value, + $Res Function(_$SCCallFunctionParamsImpl) then) = + __$$SCCallFunctionParamsImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String contract, + String function, + List args, + @JsonKey(name: 'resolve_last') bool resolveLast}); +} + +/// @nodoc +class __$$SCCallFunctionParamsImplCopyWithImpl<$Res> + extends _$SCCallFunctionParamsCopyWithImpl<$Res, _$SCCallFunctionParamsImpl> + implements _$$SCCallFunctionParamsImplCopyWith<$Res> { + __$$SCCallFunctionParamsImplCopyWithImpl(_$SCCallFunctionParamsImpl _value, + $Res Function(_$SCCallFunctionParamsImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? contract = null, + Object? function = null, + Object? args = null, + Object? resolveLast = null, + }) { + return _then(_$SCCallFunctionParamsImpl( + contract: null == contract + ? _value.contract + : contract // ignore: cast_nullable_to_non_nullable + as String, + function: null == function + ? _value.function + : function // ignore: cast_nullable_to_non_nullable + as String, + args: null == args + ? _value._args + : args // ignore: cast_nullable_to_non_nullable + as List, + resolveLast: null == resolveLast + ? _value.resolveLast + : resolveLast // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$SCCallFunctionParamsImpl implements _SCCallFunctionParams { + _$SCCallFunctionParamsImpl( + {required this.contract, + required this.function, + required final List args, + @JsonKey(name: 'resolve_last') this.resolveLast = true}) + : _args = args; + + factory _$SCCallFunctionParamsImpl.fromJson(Map json) => + _$$SCCallFunctionParamsImplFromJson(json); + + @override + final String contract; + @override + final String function; + final List _args; + @override + List get args { + if (_args is EqualUnmodifiableListView) return _args; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_args); + } + + @override + @JsonKey(name: 'resolve_last') + final bool resolveLast; + + @override + String toString() { + return 'SCCallFunctionParams(contract: $contract, function: $function, args: $args, resolveLast: $resolveLast)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SCCallFunctionParamsImpl && + (identical(other.contract, contract) || + other.contract == contract) && + (identical(other.function, function) || + other.function == function) && + const DeepCollectionEquality().equals(other._args, _args) && + (identical(other.resolveLast, resolveLast) || + other.resolveLast == resolveLast)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, contract, function, + const DeepCollectionEquality().hash(_args), resolveLast); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SCCallFunctionParamsImplCopyWith<_$SCCallFunctionParamsImpl> + get copyWith => + __$$SCCallFunctionParamsImplCopyWithImpl<_$SCCallFunctionParamsImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$SCCallFunctionParamsImplToJson( + this, + ); + } +} + +abstract class _SCCallFunctionParams implements SCCallFunctionParams { + factory _SCCallFunctionParams( + {required final String contract, + required final String function, + required final List args, + @JsonKey(name: 'resolve_last') final bool resolveLast}) = + _$SCCallFunctionParamsImpl; + + factory _SCCallFunctionParams.fromJson(Map json) = + _$SCCallFunctionParamsImpl.fromJson; + + @override + String get contract; + @override + String get function; + @override + List get args; + @override + @JsonKey(name: 'resolve_last') + bool get resolveLast; + @override + @JsonKey(ignore: true) + _$$SCCallFunctionParamsImplCopyWith<_$SCCallFunctionParamsImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/src/model/smart_contracts/sc_call_function_params.g.dart b/lib/src/model/smart_contracts/sc_call_function_params.g.dart new file mode 100644 index 0000000..10b5c2d --- /dev/null +++ b/lib/src/model/smart_contracts/sc_call_function_params.g.dart @@ -0,0 +1,25 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'sc_call_function_params.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$SCCallFunctionParamsImpl _$$SCCallFunctionParamsImplFromJson( + Map json) => + _$SCCallFunctionParamsImpl( + contract: json['contract'] as String, + function: json['function'] as String, + args: json['args'] as List, + resolveLast: json['resolve_last'] as bool? ?? true, + ); + +Map _$$SCCallFunctionParamsImplToJson( + _$SCCallFunctionParamsImpl instance) => + { + 'contract': instance.contract, + 'function': instance.function, + 'args': instance.args, + 'resolve_last': instance.resolveLast, + }; diff --git a/lib/src/model/smart_contracts/sc_call_function_request.dart b/lib/src/model/smart_contracts/sc_call_function_request.dart index f50638b..2a99834 100644 --- a/lib/src/model/smart_contracts/sc_call_function_request.dart +++ b/lib/src/model/smart_contracts/sc_call_function_request.dart @@ -1,4 +1,5 @@ /// SPDX-License-Identifier: AGPL-3.0-or-later +import 'package:archethic_lib_dart/src/model/smart_contracts/sc_call_function_params.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'sc_call_function_request.freezed.dart'; @@ -16,15 +17,3 @@ class SCCallFunctionRequest with _$SCCallFunctionRequest { factory SCCallFunctionRequest.fromJson(Map json) => _$SCCallFunctionRequestFromJson(json); } - -@freezed -class SCCallFunctionParams with _$SCCallFunctionParams { - factory SCCallFunctionParams({ - required String contract, - required String function, - required List args, - }) = _SCCallFunctionParams; - - factory SCCallFunctionParams.fromJson(Map json) => - _$SCCallFunctionParamsFromJson(json); -} diff --git a/lib/src/model/smart_contracts/sc_call_function_request.freezed.dart b/lib/src/model/smart_contracts/sc_call_function_request.freezed.dart index fe1e9b1..3e79445 100644 --- a/lib/src/model/smart_contracts/sc_call_function_request.freezed.dart +++ b/lib/src/model/smart_contracts/sc_call_function_request.freezed.dart @@ -228,189 +228,3 @@ abstract class _SCCallFunctionRequest implements SCCallFunctionRequest { _$$SCCallFunctionRequestImplCopyWith<_$SCCallFunctionRequestImpl> get copyWith => throw _privateConstructorUsedError; } - -SCCallFunctionParams _$SCCallFunctionParamsFromJson(Map json) { - return _SCCallFunctionParams.fromJson(json); -} - -/// @nodoc -mixin _$SCCallFunctionParams { - String get contract => throw _privateConstructorUsedError; - String get function => throw _privateConstructorUsedError; - List get args => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $SCCallFunctionParamsCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $SCCallFunctionParamsCopyWith<$Res> { - factory $SCCallFunctionParamsCopyWith(SCCallFunctionParams value, - $Res Function(SCCallFunctionParams) then) = - _$SCCallFunctionParamsCopyWithImpl<$Res, SCCallFunctionParams>; - @useResult - $Res call({String contract, String function, List args}); -} - -/// @nodoc -class _$SCCallFunctionParamsCopyWithImpl<$Res, - $Val extends SCCallFunctionParams> - implements $SCCallFunctionParamsCopyWith<$Res> { - _$SCCallFunctionParamsCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? contract = null, - Object? function = null, - Object? args = null, - }) { - return _then(_value.copyWith( - contract: null == contract - ? _value.contract - : contract // ignore: cast_nullable_to_non_nullable - as String, - function: null == function - ? _value.function - : function // ignore: cast_nullable_to_non_nullable - as String, - args: null == args - ? _value.args - : args // ignore: cast_nullable_to_non_nullable - as List, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$SCCallFunctionParamsImplCopyWith<$Res> - implements $SCCallFunctionParamsCopyWith<$Res> { - factory _$$SCCallFunctionParamsImplCopyWith(_$SCCallFunctionParamsImpl value, - $Res Function(_$SCCallFunctionParamsImpl) then) = - __$$SCCallFunctionParamsImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({String contract, String function, List args}); -} - -/// @nodoc -class __$$SCCallFunctionParamsImplCopyWithImpl<$Res> - extends _$SCCallFunctionParamsCopyWithImpl<$Res, _$SCCallFunctionParamsImpl> - implements _$$SCCallFunctionParamsImplCopyWith<$Res> { - __$$SCCallFunctionParamsImplCopyWithImpl(_$SCCallFunctionParamsImpl _value, - $Res Function(_$SCCallFunctionParamsImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? contract = null, - Object? function = null, - Object? args = null, - }) { - return _then(_$SCCallFunctionParamsImpl( - contract: null == contract - ? _value.contract - : contract // ignore: cast_nullable_to_non_nullable - as String, - function: null == function - ? _value.function - : function // ignore: cast_nullable_to_non_nullable - as String, - args: null == args - ? _value._args - : args // ignore: cast_nullable_to_non_nullable - as List, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$SCCallFunctionParamsImpl implements _SCCallFunctionParams { - _$SCCallFunctionParamsImpl( - {required this.contract, - required this.function, - required final List args}) - : _args = args; - - factory _$SCCallFunctionParamsImpl.fromJson(Map json) => - _$$SCCallFunctionParamsImplFromJson(json); - - @override - final String contract; - @override - final String function; - final List _args; - @override - List get args { - if (_args is EqualUnmodifiableListView) return _args; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_args); - } - - @override - String toString() { - return 'SCCallFunctionParams(contract: $contract, function: $function, args: $args)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$SCCallFunctionParamsImpl && - (identical(other.contract, contract) || - other.contract == contract) && - (identical(other.function, function) || - other.function == function) && - const DeepCollectionEquality().equals(other._args, _args)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash(runtimeType, contract, function, - const DeepCollectionEquality().hash(_args)); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$SCCallFunctionParamsImplCopyWith<_$SCCallFunctionParamsImpl> - get copyWith => - __$$SCCallFunctionParamsImplCopyWithImpl<_$SCCallFunctionParamsImpl>( - this, _$identity); - - @override - Map toJson() { - return _$$SCCallFunctionParamsImplToJson( - this, - ); - } -} - -abstract class _SCCallFunctionParams implements SCCallFunctionParams { - factory _SCCallFunctionParams( - {required final String contract, - required final String function, - required final List args}) = _$SCCallFunctionParamsImpl; - - factory _SCCallFunctionParams.fromJson(Map json) = - _$SCCallFunctionParamsImpl.fromJson; - - @override - String get contract; - @override - String get function; - @override - List get args; - @override - @JsonKey(ignore: true) - _$$SCCallFunctionParamsImplCopyWith<_$SCCallFunctionParamsImpl> - get copyWith => throw _privateConstructorUsedError; -} diff --git a/lib/src/model/smart_contracts/sc_call_function_request.g.dart b/lib/src/model/smart_contracts/sc_call_function_request.g.dart index 765cab7..aa3c0fc 100644 --- a/lib/src/model/smart_contracts/sc_call_function_request.g.dart +++ b/lib/src/model/smart_contracts/sc_call_function_request.g.dart @@ -24,19 +24,3 @@ Map _$$SCCallFunctionRequestImplToJson( 'id': instance.id, 'params': instance.params, }; - -_$SCCallFunctionParamsImpl _$$SCCallFunctionParamsImplFromJson( - Map json) => - _$SCCallFunctionParamsImpl( - contract: json['contract'] as String, - function: json['function'] as String, - args: json['args'] as List, - ); - -Map _$$SCCallFunctionParamsImplToJson( - _$SCCallFunctionParamsImpl instance) => - { - 'contract': instance.contract, - 'function': instance.function, - 'args': instance.args, - }; diff --git a/pubspec.yaml b/pubspec.yaml index 901c8c7..75ccaa5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ name: archethic_lib_dart description: Archethic dart library for Flutter for Node and Browser. This library aims to provide a easy way to create Archethic transaction and to send them over the network homepage: https://github.com/archethic-foundation/libdart -version: 3.3.16 +version: 3.3.17 environment: sdk: ">=3.3.0 <4.0.0" diff --git a/test/api_test.dart b/test/api_test.dart index a66af14..d878e78 100644 --- a/test/api_test.dart +++ b/test/api_test.dart @@ -4,6 +4,7 @@ import 'dart:developer'; import 'package:archethic_lib_dart/src/model/address.dart'; import 'package:archethic_lib_dart/src/model/exception/archethic_json_rpc_exception.dart'; +import 'package:archethic_lib_dart/src/model/smart_contracts/sc_call_function_params.dart'; import 'package:archethic_lib_dart/src/model/smart_contracts/sc_call_function_request.dart'; import 'package:archethic_lib_dart/src/model/transaction.dart'; import 'package:archethic_lib_dart/src/services/api_service.dart'; @@ -261,6 +262,49 @@ void main() { ); }); + test('callSCFunctionWithResolveLastFalse', () async { + final smCallFunctionResponse = + await ApiService('https://testnet.archethic.net').callSCFunction( + jsonRPCRequest: SCCallFunctionRequest( + method: 'contract_fun', + params: SCCallFunctionParams( + contract: + '0000A6BC173C4EDB141066FBB029C6E5696A4210241835460CB2964AB0D02449CEA6', + function: 'info', + args: [], + resolveLast: false, + ), + ), + ); + log('smCallFunctionResponse: $smCallFunctionResponse'); + + expect( + smCallFunctionResponse, + '{ae_pool: 000066706D704329CA8C2A4153991E2DDACC968622CA10217CA14952EB7ABB966C30, evm_pool: CFBA4FA32527BFF23E073406C772E9A8B8D02650, status: 0}', + ); + }); + + test('callSCFunctionWithResolveLastTrue', () async { + final smCallFunctionResponse = + await ApiService('https://testnet.archethic.net').callSCFunction( + jsonRPCRequest: SCCallFunctionRequest( + method: 'contract_fun', + params: SCCallFunctionParams( + contract: + '0000A6BC173C4EDB141066FBB029C6E5696A4210241835460CB2964AB0D02449CEA6', + function: 'info', + args: [], + ), + ), + ); + log('smCallFunctionResponse: $smCallFunctionResponse'); + + expect( + smCallFunctionResponse, + '{ae_pool: 000066706D704329CA8C2A4153991E2DDACC968622CA10217CA14952EB7ABB966C30, evm_contract: 291682232D3F2AEB5D1925E31F7876BA194939FC, evm_pool: CFBA4FA32527BFF23E073406C772E9A8B8D02650, status: 1}', + ); + }); + test('callSCFunction batch', () async { final smCallFunctionResponse = await ApiService('https://testnet.archethic.net')