Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnetwork committed Jan 11, 2024
1 parent 15cf60b commit 7e7df54
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 137 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.0
- Resolved encoding and decoding issues with Tron operations..
- Corrected Eip1559 fee calculation in ETHTransactionBuilder.
- Updated dependencies to ensure compatibility and leverage the latest features.

## 0.0.1

* TODO: Release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() async {
}

/// now get all permission (active and owner)
final List<AccountPermission> permissions = [
final List<AccountPermissionModel> permissions = [
sig.ownerPermission,
...sig.activePermissions
];
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies:
path: ../
web_socket_channel: ^2.4.0
http: ^1.1.0
blockchain_utils: ^1.5.0
blockchain_utils: ^1.6.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
Expand Down
29 changes: 0 additions & 29 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:example/main.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);

// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();

// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
2 changes: 2 additions & 0 deletions lib/address/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
abstract class BaseHexAddress {
/// Converts the hexadecimal address to a bytes.
List<int> toBytes();

String toHex();
}
8 changes: 8 additions & 0 deletions lib/ethereum/address/evm_address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ class ETHAddress implements BaseHexAddress {
String toString() {
return address;
}

/// Constant representing the length of the ETH address in bytes
static const int lengthInBytes = 21;

@override
String toHex() {
return address;
}
}
6 changes: 3 additions & 3 deletions lib/ethereum/transaction/eth_transaction_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class ETHTransactionBuilder {
_gasPrice = await rpc.request(RPCGetGasPrice());
} else {
final historical = await rpc.request(RPCGetFeeHistory(
blockCount: 20,
blockCount: 10,
newestBlock: BlockTagOrNumber.pending,
rewardPercentiles: [25, 50, 75]));
if (historical == null) {
Expand Down Expand Up @@ -281,8 +281,8 @@ class ETHTransactionBuilder {
if (_type == null) {
final historical = await rpc.request(RPCGetFeeHistory(
blockCount: 20,
newestBlock: BlockTagOrNumber.pending,
rewardPercentiles: [25, 50, 75]));
newestBlock: BlockTagOrNumber.latest,
rewardPercentiles: [25, 60, 90]));
if (historical != null) {
_type = ETHTransactionType.eip1559;
} else {
Expand Down
17 changes: 16 additions & 1 deletion lib/tron/address/tron_address.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:on_chain/address/core.dart';
import 'package:blockchain_utils/bip/address/trx_addr.dart';
import 'package:blockchain_utils/blockchain_utils.dart';
import 'package:on_chain/ethereum/address/evm_address.dart';

/// Class representing a Tron address, implementing the BaseHexAddress interface
class TronAddress implements BaseHexAddress {
Expand Down Expand Up @@ -28,7 +29,7 @@ class TronAddress implements BaseHexAddress {
factory TronAddress(String address, {bool? visible}) {
try {
if (visible == null) {
if (StringUtils.isHex(address)) {
if (StringUtils.isHexBytes(address)) {
return TronAddress.fromBytes(BytesUtils.fromHexString(address));
}
final decode = TrxAddrDecoder().decodeAddr(address);
Expand Down Expand Up @@ -84,4 +85,18 @@ class TronAddress implements BaseHexAddress {

/// Constant representing the length of the Tron address in bytes
static const int lengthInBytes = 21;

/// To Ethereum address
ETHAddress toETHAddress() {
final toBytes = BytesUtils.fromHexString(_hexAddress);

/// remove tron 0x41 prefix from bytes
return ETHAddress.fromBytes(
toBytes.sublist(toBytes.length - ETHAddress.lengthInBytes));
}

@override
String toHex() {
return _hexAddress;
}
}
16 changes: 8 additions & 8 deletions lib/tron/models/contract/account/permission_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ class PermissionType implements TronEnumerate {
/// Returns the [PermissionType] associated with the given [name].
///
/// Returns `null` if no match is found.
static PermissionType? fromName(String? name) {
try {
return values.firstWhere((element) => element.name == name);
} on StateError {
return null;
}
static PermissionType fromName(String? name,
{PermissionType? defaultPermission}) {
return values.firstWhere((element) => element.name == name,
orElse: defaultPermission == null ? null : () => defaultPermission);
}

/// Returns the [PermissionType] associated with the given [value].
///
/// Throws an error if no match is found.
static PermissionType fromValue(int value) {
return values.firstWhere((element) => element.value == value);
static PermissionType fromValue(int value,
{PermissionType? defaultPermission}) {
return values.firstWhere((element) => element.value == value,
orElse: defaultPermission == null ? null : () => defaultPermission);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ParsedSmartContractRequest {

String? get error => isSuccess
? null
: (respose["result"]["message"] as String?)?.split(":").last.trim() ??
: (respose["result"]["message"] as String?) ??
"${respose["transaction"]?["ret"]}";
@override
String toString() {
Expand Down
6 changes: 3 additions & 3 deletions lib/tron/provider/methods/get_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:on_chain/tron/provider/models/account_info.dart';
/// Query information about an account, including TRX balance, TRC-10 balances, stake information and vote information and permissions etc.
/// [developers.tron.network](https://developers.tron.network/reference/account-getaccount).
class TronRequestGetAccount
extends TVMRequestParam<TronAccount?, Map<String, dynamic>> {
extends TVMRequestParam<TronAccountModel?, Map<String, dynamic>> {
TronRequestGetAccount({required this.address, this.visible = true});

/// address
Expand All @@ -23,11 +23,11 @@ class TronRequestGetAccount
}

@override
TronAccount? onResonse(result) {
TronAccountModel? onResonse(result) {
if (result.isEmpty) {
return null;
}
return TronAccount.fromJson(result);
return TronAccountModel.fromJson(result);
}

@override
Expand Down
6 changes: 3 additions & 3 deletions lib/tron/provider/methods/get_account_resource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:on_chain/tron/provider/models/account_resource.dart';
/// Query the resource information of an account(bandwidth,energy,etc).
/// [developers.tron.network](https://developers.tron.network/reference/getaccountresource).
class TronRequestGetAccountResource
extends TVMRequestParam<AccountResource, Map<String, dynamic>> {
extends TVMRequestParam<AccountResourceModel, Map<String, dynamic>> {
TronRequestGetAccountResource({required this.address, this.visible = true});

/// Address
Expand All @@ -24,8 +24,8 @@ class TronRequestGetAccountResource
}

@override
AccountResource onResonse(result) {
return AccountResource.fromJson(result);
AccountResourceModel onResonse(result) {
return AccountResourceModel.fromJson(result);
}

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/tron/provider/methods/get_brokerage.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:on_chain/tron/address/tron_address.dart';
import 'package:on_chain/tron/provider/core/request.dart';
import 'package:on_chain/tron/provider/methods/request_methods.dart';
import 'package:on_chain/tron/provider/models/account_info.dart';

/// Get SR brokerage ratio
/// [developers.tron.network](https://developers.tron.network/reference/wallet-getbrokerage).
Expand All @@ -9,7 +9,7 @@ class TronRequestGetBrokerage
TronRequestGetBrokerage({required this.address, this.visible = true});

/// Super representative's account address
final TronAccount address;
final TronAddress address;
@override
final bool visible;

Expand Down
Loading

0 comments on commit 7e7df54

Please sign in to comment.