Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
karlprieb committed Sep 21, 2023
1 parent a8d8e68 commit 24fccb7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/src/streams/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ class TransactionDeepHashError extends StreamTransactionError {}
class TransactionSignatureError extends StreamTransactionError {}

class TransactionGetOwnerError extends StreamTransactionError {}

class GetTxAnchorError extends StreamTransactionError {}

class GetTxPriceError extends StreamTransactionError {}
39 changes: 36 additions & 3 deletions lib/src/streams/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:typed_data';

import 'package:arweave/src/api/api.dart';
import 'package:arweave/src/models/models.dart';
import 'package:arweave/src/streams/transaction.dart';
import 'package:async/async.dart';
import 'package:fpdart/fpdart.dart';

Expand Down Expand Up @@ -177,6 +176,16 @@ TaskEither<StreamTransactionError, Uint8List> serializeTagsTaskEither(
}, (error, _) => SerializeTagsError());
}

class PrepareChunksResult {
final TransactionChunksWithProofs chunks;
final String dataRoot;

PrepareChunksResult({
required this.chunks,
required this.dataRoot,
});
}

TaskEither<StreamTransactionError, PrepareChunksResult> prepareChunksTaskEither(
final DataStreamGenerator dataStreamGenerator,
) {
Expand Down Expand Up @@ -220,5 +229,29 @@ Stream<TransactionChunk> getChunks(Stream<Uint8List> dataStream,
await chunker.cancel();
}

Future<String> getTransactionAnchor() =>
ArweaveApi().get('tx_anchor').then((res) => res.body);
TaskEither<StreamTransactionError, String> getTxAnchor(String? anchor) {
if (anchor != null) {
return TaskEither.of(anchor);
}

return TaskEither.tryCatch(() async {
return await ArweaveApi().get('tx_anchor').then((res) => res.body);
}, (error, _) => GetTxAnchorError());
}

TaskEither<StreamTransactionError, BigInt> getTxPrice(
BigInt? reward, int byteSize, String? targetAddress) {
if (reward != null) {
return TaskEither.of(reward);
}

final endpoint = targetAddress != null
? 'price/$byteSize/$targetAddress'
: 'price/$byteSize';

return TaskEither.tryCatch(() async {
return await ArweaveApi()
.get(endpoint)
.then((res) => BigInt.parse(res.body));
}, (error, _) => GetTxPriceError());
}

0 comments on commit 24fccb7

Please sign in to comment.