Skip to content

Commit

Permalink
chore: ➖ Remove Archive dep
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Jan 13, 2025
1 parent aaf54ad commit 4f51487
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 59 deletions.
29 changes: 0 additions & 29 deletions lib/src/model/contract.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'dart:convert';
import 'package:archethic_lib_dart/src/model/transaction.dart';
import 'package:archive/archive.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'contract.freezed.dart';
Expand Down Expand Up @@ -55,40 +53,13 @@ class Contract with _$Contract {
const factory Contract({
required String? bytecode,
required ContractManifest manifest,
@Default(true) bool compressed,
}) = _Contract;

factory Contract.fromJson(Map<String, dynamic> json) =>
_$ContractFromJson(json);

factory Contract.withUncompressedBytecode({
required String? bytecode,
required ContractManifest manifest,
}) {
if (bytecode == null) {
throw ArgumentError('Bytecode cannot be null');
}

final compressedBytecode =
const ZLibEncoderWeb().encodeBytes(utf8.encode(bytecode), raw: true);

return Contract(
bytecode: utf8.decode(compressedBytecode),
manifest: manifest,
);
}

const Contract._();

String? getCompressedBytecode() {
return compressed
? bytecode
: utf8.decode(
const ZLibEncoderWeb()
.encodeBytes(utf8.encode(bytecode!), raw: true),
);
}

List<ContractAction> getActions() {
final actions = <ContractAction>[];
manifest.abi.functions.forEach((name, functionABI) {
Expand Down
16 changes: 0 additions & 16 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.8.0"
archive:
dependency: "direct main"
description:
name: archive
sha256: "6199c74e3db4fbfbd04f66d739e72fe11c8a8957d5f219f1f4482dbde6420b5a"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -550,14 +542,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.5.1"
posix:
dependency: transitive
description:
name: posix
sha256: a0117dc2167805aa9125b82eee515cc891819bac2f538c83646d355b16f58b9a
url: "https://pub.dev"
source: hosted
version: "6.0.1"
pub_semver:
dependency: transitive
description:
Expand Down
3 changes: 0 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ environment:
sdk: ">=3.5.3 <4.0.0"

dependencies:
# Compression
archive: ^4.0.2

# Collections and utilities functions and classes related to collections.
collection: ^1.18.0

Expand Down
17 changes: 6 additions & 11 deletions test/transaction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:archethic_lib_dart/archethic_lib_dart.dart';
import 'package:archethic_lib_dart/src/utils/crypto.dart' as crypto;
import 'package:archethic_lib_dart/src/utils/typed_encoding.dart'
as typed_encoding;
import 'package:archive/archive.dart';
import 'package:test/test.dart';

import 'utils.dart';
Expand Down Expand Up @@ -52,9 +51,9 @@ void main() {
type: 'transfer',
data: Transaction.initData(),
).setContract(
Contract.withUncompressedBytecode(
const Contract(
bytecode: '',
manifest: const ContractManifest(
manifest: ContractManifest(
abi: WasmABI(state: {}, functions: {}),
),
),
Expand All @@ -71,20 +70,16 @@ void main() {
data: Transaction.initData(),
version: 4,
).setContract(
Contract.withUncompressedBytecode(
const Contract(
bytecode: '',
manifest: const ContractManifest(
manifest: ContractManifest(
abi: WasmABI(state: {'test': 'test'}, functions: {}),
),
),
);
final decompressedBytecode = const ZLibDecoder().decodeBytes(
utf8.encode(tx.data!.contract!.bytecode!),
raw: true,
);

expect(
utf8.decode(decompressedBytecode),
tx.data!.contract!.bytecode,
'',
);
expect(tx.data!.contract!.manifest.abi.state['test'], 'test');
Expand Down Expand Up @@ -325,7 +320,7 @@ void main() {
test(
'should generate binary encoding of the transaction before signing - version 4',
() {
final contract = Contract.withUncompressedBytecode(
final contract = Contract(
bytecode: utf8.decode(Uint8List.fromList([5])),
manifest: const ContractManifest(
abi: WasmABI(
Expand Down

0 comments on commit 4f51487

Please sign in to comment.