Skip to content

Commit

Permalink
feat: implement more abi methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-A4 committed Sep 12, 2023
1 parent 7929e7b commit 89952f5
Show file tree
Hide file tree
Showing 11 changed files with 700 additions and 71 deletions.
30 changes: 30 additions & 0 deletions packages/flutter_nekoton_bridge/ios/Classes/frb.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,25 @@ void wire_unpack_contract_fields(int64_t port_,
struct wire_uint_8_list *boc,
bool allow_partial);

void wire_create_raw_external_message(int64_t port_,
struct wire_uint_8_list *dst,
struct wire_uint_8_list *state_init,
struct wire_uint_8_list *body,
uint32_t timeout);

void wire_encode_internal_message(int64_t port_,
struct wire_uint_8_list *src,
struct wire_uint_8_list *dst,
bool bounce,
struct wire_uint_8_list *state_init,
struct wire_uint_8_list *body,
struct wire_uint_8_list *amount,
bool *bounced);

void wire_make_full_account_boc(int64_t port_, struct wire_uint_8_list *account_stuff_boc);

void wire_parse_full_account_boc(int64_t port_, struct wire_uint_8_list *account);

void wire_test_logger_info(int64_t port_, struct wire_uint_8_list *string);

void wire_test_logger_debug(int64_t port_, struct wire_uint_8_list *string);
Expand Down Expand Up @@ -476,6 +495,9 @@ void wire_sign__method__UnsignedMessageImpl(int64_t port_,
struct wire_UnsignedMessageImpl *that,
struct wire_uint_8_list *signature);

void wire_sign_fake__method__UnsignedMessageImpl(int64_t port_,
struct wire_UnsignedMessageImpl *that);

void wire_new__static_method__GqlTransportImpl(int64_t port_,
struct wire_GqlConnectionDartWrapper *gql_connection);

Expand Down Expand Up @@ -964,6 +986,8 @@ struct wire_StringList *new_StringList_0(int32_t len);

struct wire_AccountsStorageImpl *new_box_autoadd_accounts_storage_impl_0(void);

bool *new_box_autoadd_bool_0(bool value);

struct wire_CallerTestClass *new_box_autoadd_caller_test_class_0(void);

struct wire_DartCallStub *new_box_autoadd_dart_call_stub_0(void);
Expand Down Expand Up @@ -1118,6 +1142,10 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) wire_execute_local);
dummy_var ^= ((int64_t) (void*) wire_unpack_init_data);
dummy_var ^= ((int64_t) (void*) wire_unpack_contract_fields);
dummy_var ^= ((int64_t) (void*) wire_create_raw_external_message);
dummy_var ^= ((int64_t) (void*) wire_encode_internal_message);
dummy_var ^= ((int64_t) (void*) wire_make_full_account_boc);
dummy_var ^= ((int64_t) (void*) wire_parse_full_account_boc);
dummy_var ^= ((int64_t) (void*) wire_test_logger_info);
dummy_var ^= ((int64_t) (void*) wire_test_logger_debug);
dummy_var ^= ((int64_t) (void*) wire_test_logger_warn);
Expand Down Expand Up @@ -1147,6 +1175,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) wire_expire_at__method__UnsignedMessageImpl);
dummy_var ^= ((int64_t) (void*) wire_hash__method__UnsignedMessageImpl);
dummy_var ^= ((int64_t) (void*) wire_sign__method__UnsignedMessageImpl);
dummy_var ^= ((int64_t) (void*) wire_sign_fake__method__UnsignedMessageImpl);
dummy_var ^= ((int64_t) (void*) wire_new__static_method__GqlTransportImpl);
dummy_var ^= ((int64_t) (void*) wire_get_contract_state__method__GqlTransportImpl);
dummy_var ^= ((int64_t) (void*) wire_get_full_contract_state__method__GqlTransportImpl);
Expand Down Expand Up @@ -1272,6 +1301,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) new_ArcUnsignedMessageBoxTrait);
dummy_var ^= ((int64_t) (void*) new_StringList_0);
dummy_var ^= ((int64_t) (void*) new_box_autoadd_accounts_storage_impl_0);
dummy_var ^= ((int64_t) (void*) new_box_autoadd_bool_0);
dummy_var ^= ((int64_t) (void*) new_box_autoadd_caller_test_class_0);
dummy_var ^= ((int64_t) (void*) new_box_autoadd_dart_call_stub_0);
dummy_var ^= ((int64_t) (void*) new_box_autoadd_dynamic_value_0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ class UnsignedMessage {
final decoded = jsonDecode(encoded) as Map<String, dynamic>;
return SignedMessage.fromJson(decoded);
}

/// Sign message without signature and return SignedMessage.
Future<SignedMessage> signFake() async {
final encoded = await message.signFake();
final decoded = jsonDecode(encoded) as Map<String, dynamic>;
return SignedMessage.fromJson(decoded);
}

void dispose() {
message.innerMessage.dispose();
}
}
62 changes: 60 additions & 2 deletions packages/flutter_nekoton_bridge/lib/nekoton/helpers/abi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ Future<String> encodeInternalInput({

/// Returns SignedMessage from nekoton or throws error
Future<SignedMessage> createExternalMessageWithoutSignature({
required String dst,
required Address dst,
required String contractAbi,
required String method,
String? stateInit,
required TokensObject input,
required Duration timeout,
}) async {
final res = await createLib().createExternalMessageWithoutSignature(
dst: dst,
dst: dst.address,
contractAbi: contractAbi,
method: method,
input: jsonEncode(input),
Expand Down Expand Up @@ -320,6 +320,12 @@ class ExecuteLocalException implements Exception {

/// Run contract locally.
/// [config] - value from [Transport.getBlockchainConfig]
/// [account] - boc from [makeFullAccountBoc]
/// [message] - base64-encoded boc from one of:
/// 1) [encodeInternalMessage]
/// 2) [createRawExternalMessage]
/// 3) [createExternalMessageWithoutSignature]
/// 4) [UnsignedMessage.signFake]
///
/// Returns [boc, transaction] if everything is ok or
/// throws [ExecuteLocalException] if transaction failed, this is not
Expand Down Expand Up @@ -384,3 +390,55 @@ Future<Map<String, dynamic>?> unpackContractFields({

return jsonDecode(result) as Map<String, dynamic>;
}

/// Create raw external message without real signing or throws error
Future<SignedMessage> createRawExternalMessage({
required Address dst,
required Duration timeout,
String? stateInit,
String? body,
}) async {
final result = await createLib().createRawExternalMessage(
dst: dst.address,
timeout: timeout.inMilliseconds,
body: body,
stateInit: stateInit,
);

return SignedMessage.fromJson(jsonDecode(result));
}

/// Returns base-64 encoded Message or throws error
Future<String> encodeInternalMessage({
required Address dst,
required bool bounce,
required BigInt amount,
Address? src,
String? stateInit,
String? body,
bool? bounced,
}) async {
return createLib().encodeInternalMessage(
dst: dst.address,
src: src?.address,
body: body,
stateInit: stateInit,
bounced: bounced,
bounce: bounce,
amount: amount.toString(),
);
}

/// Returns base-64 encoded Account or throws error
/// [accountStuffBoc] - [FullContractState.boc]
Future<String> makeFullAccountBoc(String? accountStuffBoc) {
return createLib().makeFullAccountBoc(accountStuffBoc: accountStuffBoc);
}

/// [account] - base64-encoded boc after [executeLocal]
Future<FullContractState?> parseFullAccountBoc(String account) async {
final state = await createLib().parseFullAccountBoc(account: account);
if (state == null) return null;

return FullContractState.fromJson(jsonDecode(state));
}
174 changes: 174 additions & 0 deletions packages/nekoton_bridge/lib/src/bridge_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,45 @@ abstract class NekotonBridge {

FlutterRustBridgeTaskConstMeta get kUnpackContractFieldsConstMeta;

/// Returns json-encoded SignedMessage or throws error
/// dst - destination address
/// timeout - milliseconds
Future<String> createRawExternalMessage(
{required String dst,
String? stateInit,
String? body,
required int timeout,
dynamic hint});

FlutterRustBridgeTaskConstMeta get kCreateRawExternalMessageConstMeta;

/// Returns base-64 encoded Message or throws error
/// src - address of sender
/// dst - address of destination
/// body - base64-encoded data
Future<String> encodeInternalMessage(
{String? src,
required String dst,
required bool bounce,
String? stateInit,
String? body,
required String amount,
bool? bounced,
dynamic hint});

FlutterRustBridgeTaskConstMeta get kEncodeInternalMessageConstMeta;

/// Returns base-64 encoded Account or throws error
Future<String> makeFullAccountBoc({String? accountStuffBoc, dynamic hint});

FlutterRustBridgeTaskConstMeta get kMakeFullAccountBocConstMeta;

/// Returns optional json-encoded FullContractState or throws error
/// account - base64-encoded boc after execute_local
Future<String?> parseFullAccountBoc({required String account, dynamic hint});

FlutterRustBridgeTaskConstMeta get kParseFullAccountBocConstMeta;

///----------------------------
/// CONTENT OF src/utils/tests_api.rs
///----------------------------
Expand Down Expand Up @@ -444,6 +483,13 @@ abstract class NekotonBridge {

FlutterRustBridgeTaskConstMeta get kSignMethodUnsignedMessageImplConstMeta;

/// Sign message with fake signature and return json-encoded SignedMessage or throws error
Future<String> signFakeMethodUnsignedMessageImpl(
{required UnsignedMessageImpl that, dynamic hint});

FlutterRustBridgeTaskConstMeta
get kSignFakeMethodUnsignedMessageImplConstMeta;

Future<GqlTransportImpl> newStaticMethodGqlTransportImpl(
{required GqlConnectionDartWrapper gqlConnection, dynamic hint});

Expand Down Expand Up @@ -3311,6 +3357,12 @@ class UnsignedMessageImpl {
that: this,
signature: signature,
);

/// Sign message with fake signature and return json-encoded SignedMessage or throws error
Future<String> signFake({dynamic hint}) =>
bridge.signFakeMethodUnsignedMessageImpl(
that: this,
);
}

class NekotonBridgeImpl implements NekotonBridge {
Expand Down Expand Up @@ -4073,6 +4125,108 @@ class NekotonBridgeImpl implements NekotonBridge {
argNames: ["contractAbi", "boc", "allowPartial"],
);

Future<String> createRawExternalMessage(
{required String dst,
String? stateInit,
String? body,
required int timeout,
dynamic hint}) {
var arg0 = _platform.api2wire_String(dst);
var arg1 = _platform.api2wire_opt_String(stateInit);
var arg2 = _platform.api2wire_opt_String(body);
var arg3 = api2wire_u32(timeout);
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner
.wire_create_raw_external_message(port_, arg0, arg1, arg2, arg3),
parseSuccessData: _wire2api_String,
constMeta: kCreateRawExternalMessageConstMeta,
argValues: [dst, stateInit, body, timeout],
hint: hint,
));
}

FlutterRustBridgeTaskConstMeta get kCreateRawExternalMessageConstMeta =>
const FlutterRustBridgeTaskConstMeta(
debugName: "create_raw_external_message",
argNames: ["dst", "stateInit", "body", "timeout"],
);

Future<String> encodeInternalMessage(
{String? src,
required String dst,
required bool bounce,
String? stateInit,
String? body,
required String amount,
bool? bounced,
dynamic hint}) {
var arg0 = _platform.api2wire_opt_String(src);
var arg1 = _platform.api2wire_String(dst);
var arg2 = bounce;
var arg3 = _platform.api2wire_opt_String(stateInit);
var arg4 = _platform.api2wire_opt_String(body);
var arg5 = _platform.api2wire_String(amount);
var arg6 = _platform.api2wire_opt_box_autoadd_bool(bounced);
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_encode_internal_message(
port_, arg0, arg1, arg2, arg3, arg4, arg5, arg6),
parseSuccessData: _wire2api_String,
constMeta: kEncodeInternalMessageConstMeta,
argValues: [src, dst, bounce, stateInit, body, amount, bounced],
hint: hint,
));
}

FlutterRustBridgeTaskConstMeta get kEncodeInternalMessageConstMeta =>
const FlutterRustBridgeTaskConstMeta(
debugName: "encode_internal_message",
argNames: [
"src",
"dst",
"bounce",
"stateInit",
"body",
"amount",
"bounced"
],
);

Future<String> makeFullAccountBoc({String? accountStuffBoc, dynamic hint}) {
var arg0 = _platform.api2wire_opt_String(accountStuffBoc);
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) =>
_platform.inner.wire_make_full_account_boc(port_, arg0),
parseSuccessData: _wire2api_String,
constMeta: kMakeFullAccountBocConstMeta,
argValues: [accountStuffBoc],
hint: hint,
));
}

FlutterRustBridgeTaskConstMeta get kMakeFullAccountBocConstMeta =>
const FlutterRustBridgeTaskConstMeta(
debugName: "make_full_account_boc",
argNames: ["accountStuffBoc"],
);

Future<String?> parseFullAccountBoc({required String account, dynamic hint}) {
var arg0 = _platform.api2wire_String(account);
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) =>
_platform.inner.wire_parse_full_account_boc(port_, arg0),
parseSuccessData: _wire2api_opt_String,
constMeta: kParseFullAccountBocConstMeta,
argValues: [account],
hint: hint,
));
}

FlutterRustBridgeTaskConstMeta get kParseFullAccountBocConstMeta =>
const FlutterRustBridgeTaskConstMeta(
debugName: "parse_full_account_boc",
argNames: ["account"],
);

Future<void> testLoggerInfo({required String string, dynamic hint}) {
var arg0 = _platform.api2wire_String(string);
return _platform.executeNormal(FlutterRustBridgeTask(
Expand Down Expand Up @@ -4585,6 +4739,26 @@ class NekotonBridgeImpl implements NekotonBridge {
argNames: ["that", "signature"],
);

Future<String> signFakeMethodUnsignedMessageImpl(
{required UnsignedMessageImpl that, dynamic hint}) {
var arg0 = _platform.api2wire_box_autoadd_unsigned_message_impl(that);
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner
.wire_sign_fake__method__UnsignedMessageImpl(port_, arg0),
parseSuccessData: _wire2api_String,
constMeta: kSignFakeMethodUnsignedMessageImplConstMeta,
argValues: [that],
hint: hint,
));
}

FlutterRustBridgeTaskConstMeta
get kSignFakeMethodUnsignedMessageImplConstMeta =>
const FlutterRustBridgeTaskConstMeta(
debugName: "sign_fake__method__UnsignedMessageImpl",
argNames: ["that"],
);

Future<GqlTransportImpl> newStaticMethodGqlTransportImpl(
{required GqlConnectionDartWrapper gqlConnection, dynamic hint}) {
var arg0 = _platform
Expand Down
Loading

0 comments on commit 89952f5

Please sign in to comment.