Skip to content

Commit

Permalink
feat: add interface function related to specific fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
y-pakorn committed Sep 16, 2021
1 parent 3093c89 commit dead6c6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/src/ethers/interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,25 @@ class Interface extends Interop<_InterfaceImpl> {

const Interface._(_InterfaceImpl impl) : super.internal(impl);

/// The [ConstructorFragment] for the interface.
ConstructorFragment get deploy => ConstructorFragment._(impl.deploy);

/// All the [EventFragment] in the interface.
List<EventFragment> get events => impl.events
.cast<_EventFragmentImpl>()
.map((e) => EventFragment._(e))
.toList();

/// All the [Fragment] in the interface.
List<Fragment> get fragments =>
impl.fragments.cast<_FragmentImpl>().map((e) => Fragment._(e)).toList();

/// All the [FunctionFragment] in the interface.
List<FunctionFragment> get functions => impl.functions
.cast<_FunctionFragmentImpl>()
.map((e) => FunctionFragment._(e))
.toList();

/// Returns the decoded values from the result of a call for [function] (see Specifying Fragments) for the given [data].
///
/// ---
Expand Down Expand Up @@ -228,6 +243,13 @@ class Interface extends Interop<_InterfaceImpl> {
/// ```
List<String> formatMinimal() => (format(FormatTypes.minimal) as List).cast();

/// Returns the [FunctionFragment] for [event].
EventFragment getEvent(String event) => EventFragment._(impl.getEvent(event));

/// Returns the [FunctionFragment] for [event] fragment.
EventFragment getEventFromFragment(Fragment event) =>
EventFragment._(impl.getEvent(event.impl));

/// Return the topic hash for [event].
///
/// ---
Expand All @@ -241,6 +263,14 @@ class Interface extends Interop<_InterfaceImpl> {
/// ```
String getEventTopic(String event) => impl.getEventTopic(event);

/// Returns the [FunctionFragment] for [function].
FunctionFragment getFunction(String function) =>
FunctionFragment._(impl.getFunction(function));

/// Returns the [FunctionFragment] for [function] fragment.
FunctionFragment getFunctionFromFragment(Fragment function) =>
FunctionFragment._(impl.getFunction(function.impl));

/// Return the sighash (or Function Selector) for [function].
///
/// ---
Expand Down
10 changes: 10 additions & 0 deletions lib/src/ethers/interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,14 @@ class _FunctionFragmentImpl extends _ConstructorFragmentImpl {
class _InterfaceImpl {
external _InterfaceImpl(dynamic abi);

external _ConstructorFragmentImpl get deploy;

external List<_EventFragmentImpl> get events;

external List<_FragmentImpl> get fragments;

external List<_FunctionFragmentImpl> get functions;

external List decodeFunctionResult(dynamic fragment, String data);

external List encodeFilterTopics(dynamic fragment, List values);
Expand All @@ -168,8 +174,12 @@ class _InterfaceImpl {

external dynamic format([dynamic types]);

external _EventFragmentImpl getEvent(dynamic fragment);

external String getEventTopic(String event);

external _FunctionFragmentImpl getFunction(dynamic fragment);

external String getSighash(dynamic function);
}

Expand Down

0 comments on commit dead6c6

Please sign in to comment.