Skip to content

Commit

Permalink
Merge pull request #201 from Topl/RIBN-542
Browse files Browse the repository at this point in the history
Updates to documentation of models
  • Loading branch information
KalervoHyyppa authored Dec 21, 2022
2 parents 121cff4 + 4a0b89b commit 6f871e5
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 30 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Ribn allows users to:
## Build locally
* Ensure you have [Node.js](https://nodejs.org) v16 installed.
* Recommended: If you are using nvm, you can run `nvm use` to install the right Node version.
* Ensure you have [Flutter](https://docs.flutter.dev/get-started/install) v2 installed.
* Ensure you have the latest version of [Flutter](https://docs.flutter.dev/get-started/install) installed.
* Install dependencies
* Install [git-lfs](https://docs.github.com/en/repositories/working-with-files/managing-large-files/installing-git-large-file-storage) **BEFORE** running `flutter pub get`
* Install Flutter dependencies: `flutter pub get`
* Install Node dependencies: `npm install`
* Bundle [extension scripts](web/src/) using webpack: `npm run build`
Expand Down
93 changes: 72 additions & 21 deletions lib/models/raw_tx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,45 @@ RawTx rawTxFromJson(String str) => RawTx.fromJson(json.decode(str));
String rawTxToJson(RawTx data) => json.encode(data.toJson());

class RawTx {
/// Transfer Type from Bifrost. Can be three different types:
/// [PolyTransfer](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/modifier/transaction/PolyTransfer.scala),
/// [AssetTransfer](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/modifier/transaction/AssetTransfer.scala),
/// [ArbitTransfer](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/modifier/transaction/ArbitTransfer.scala)
final String txType;

/// The time stamp of the transaction
final int timestamp;

/// The number of boxes that were generated with this transaction.
final List<NewBox> newBoxes;

/// Byte data represented by Latin-1 encoded text. [Latin1Data](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/utils/StringDataTypes.scala)
final dynamic data;

/// The sender/s address/s of this transaction.
final List<List<String>> from;

/// Whether this transfer will be a minting transfer
final bool minting;

/// The Id of the transaction
final String txId;

/// The boxes that will be deleted as a result of this transaction
final List<String> boxesToRemove;

/// Fee to be paid to the network for the transaction (unit is nanoPoly)
final String fee;

/// The recipient/s address/s of this transaction.
final List<List<dynamic>> to;

/// The propositionType that has or will be used by the sender to generate the proposition eg., PublicKeyCurve25519, ThresholdCurve25519. [Proposition](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/attestation/Proposition.scala)
final String propositionType;

/// The message that will have to be signed by the sender of this transaction
final String messageToSign;

RawTx({
required this.txType,
required this.timestamp,
Expand All @@ -24,33 +63,21 @@ class RawTx {
required this.messageToSign,
});

final String txType;
final int timestamp;
final List<NewBox> newBoxes;
final dynamic data;
final List<List<String>> from;
final bool minting;
final String txId;
final List<String> boxesToRemove;
final String fee;
final List<List<dynamic>> to;
final String propositionType;
final String messageToSign;

factory RawTx.fromJson(Map<String, dynamic> json) => RawTx(
txType: json['txType'],
timestamp: json['timestamp'],
newBoxes:
List<NewBox>.from(json['newBoxes'].map((x) => NewBox.fromJson(x))),
newBoxes: List<NewBox>.from(json['newBoxes'].map((x) => NewBox.fromJson(x))),
data: json['data'],
from: List<List<String>>.from(
json['from'].map((x) => List<String>.from(x.map((x) => x))),),
json['from'].map((x) => List<String>.from(x.map((x) => x))),
),
minting: json['minting'],
txId: json['txId'],
boxesToRemove: List<String>.from(json['boxesToRemove'].map((x) => x)),
fee: json['fee'],
to: List<List<dynamic>>.from(
json['to'].map((x) => List<dynamic>.from(x.map((x) => x))),),
json['to'].map((x) => List<dynamic>.from(x.map((x) => x))),
),
propositionType: json['propositionType'],
messageToSign: json['messageToSign'],
);
Expand All @@ -61,18 +88,21 @@ class RawTx {
'newBoxes': List<dynamic>.from(newBoxes.map((x) => x.toJson())),
'data': data,
'from': List<dynamic>.from(
from.map((x) => List<dynamic>.from(x.map((x) => x))),),
from.map((x) => List<dynamic>.from(x.map((x) => x))),
),
'minting': minting,
'txId': txId,
'boxesToRemove': List<dynamic>.from(boxesToRemove.map((x) => x)),
'fee': fee,
'to': List<dynamic>.from(
to.map((x) => List<dynamic>.from(x.map((x) => x))),),
to.map((x) => List<dynamic>.from(x.map((x) => x))),
),
'propositionType': propositionType,
'messageToSign': messageToSign,
};
}

/// [TokenBox](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/modifier/box/Box.scala)
class NewBox {
NewBox({
required this.nonce,
Expand All @@ -82,10 +112,22 @@ class NewBox {
required this.value,
});

/// Number used once
final String nonce;

/// Id of boxs
final String id;

/// Evidence content serves as a fingerprint (or commitment) of a particular proposition that is used to lock a box. [Evidence](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/attestation/Evidence.scala)
final String evidence;

/// Type of box. Can be 3 types:
/// [ArbitBox](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/modifier/box/ArbitBox.scala),
/// [PolyBox](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/modifier/box/PolyBox.scala),
/// [AssetBox](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/modifier/box/AssetBox.scala)
final String type;

/// Value of box
final Value value;

factory NewBox.fromJson(Map<String, dynamic> json) => NewBox(
Expand Down Expand Up @@ -114,19 +156,28 @@ class Value {
required this.securityRoot,
});

/// Can either be [Simple](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/modifier/box/TokenValueHolder.scala) of
/// [Asset](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/modifier/box/TokenValueHolder.scala)
final String type;

/// Quantity of box, unit is in nanoPolys
final String quantity;

/// AssetCode serves as a unique identifier for user issued assets [AssetCode](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/modifier/box/AssetCode.scala)
final String assetCode;

/// Additional [Latin1Data](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/utils/StringDataTypes.scala) MetaData
final dynamic metadata;

/// [SecurityRoot](https://github.com/Topl/Bifrost/blob/main/common/src/main/scala/co/topl/modifier/box/SecurityRoot.scala)
final String securityRoot;

factory Value.fromJson(Map<String, dynamic> json) => Value(
type: json['type'],
quantity: json['quantity'],
assetCode: json['assetCode'],
metadata: json['metadata'],
securityRoot:
json['securityRoot'],
securityRoot: json['securityRoot'],
);

Map<String, dynamic> toJson() => {
Expand Down
28 changes: 26 additions & 2 deletions lib/models/transfer_details.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@

import 'dart:typed_data';
import 'package:brambldart/brambldart.dart';
import 'package:flutter/foundation.dart';
import 'package:ribn/constants/rules.dart';
import 'package:ribn/models/asset_details.dart';
import 'package:ribn/models/ribn_address.dart';


/// A helper class to hold all the details for a transfer being initiated inside Ribn.
class TransferDetails {
/// The type of transfer
final TransferType transferType;

/// The amount being transferred in nanoPoly's
final String amount;

/// Address of the recipient
final String recipient;

/// The sender/s address/s of this transaction.
final List<RibnAddress> senders;

/// Extra data pertaining to transfer
final String data;

/// The address to send leftover [Poly] tokens
final RibnAddress? change;

/// The address to send leftover [Asset] and [Arbit] tokens
final RibnAddress? consolidation;

/// AssetCode serves as a unique identifier for user issued assets
final AssetCode? assetCode;

/// The networkId for returning correct transaction data per each Topl network
final int? networkId;

/// Receipt for the transaction
final TransactionReceipt? transactionReceipt;

/// The message that will have to be signed by the sender of this transaction
final Uint8List? messageToSign;

/// The id of this transaction
final String? transactionId;

/// User defined asset details.
final AssetDetails? assetDetails;

TransferDetails({
required this.transferType,
required this.amount,
Expand Down
15 changes: 9 additions & 6 deletions lib/presentation/asset_details/asset_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'package:ribn/constants/routes.dart';
import 'package:ribn/constants/strings.dart';
import 'package:ribn/models/app_state.dart';
import 'package:ribn/models/asset_details.dart';
import 'package:ribn/presentation/asset_details/asset_detail_edit_sections.dart/asset_icon_edit_section.dart';
import 'package:ribn/presentation/asset_details/asset_detail_edit_sections.dart/asset_long_name_edit_section.dart';
import 'package:ribn/presentation/asset_details/asset_detail_edit_sections.dart/asset_unit_edit_section.dart';
import 'package:ribn/presentation/asset_details/asset_detail_edit_sections/asset_icon_edit_section.dart';
import 'package:ribn/presentation/asset_details/asset_detail_edit_sections/asset_long_name_edit_section.dart';
import 'package:ribn/presentation/asset_details/asset_detail_edit_sections/asset_unit_edit_section.dart';
import 'package:ribn/presentation/asset_details/asset_detail_items/asset_amount_details.dart';
import 'package:ribn/presentation/asset_details/asset_detail_items/asset_code_details.dart';
import 'package:ribn/presentation/asset_details/asset_detail_items/asset_code_short_details.dart';
Expand Down Expand Up @@ -148,23 +148,26 @@ class _AssetDetailsPageState extends State<AssetDetailsPage> with RouteAware {
key: assetUnitKey,
currUnit: assetDetails?.unit,
editingSectionOpened: editingAssetUnit,
onEditPressed: () => _onEditPressed(key: assetUnitKey, assetDetails: assetDetails),
onEditPressed: () =>
_onEditPressed(key: assetUnitKey, assetDetails: assetDetails),
),
_buildDivider(),
// asset long name display - can be edited
AssetLongNameDetails(
key: assetLongNameKey,
currLongName: assetDetails?.longName,
editingSectionOpened: editingAssetLongName,
onEditPressed: () => _onEditPressed(key: assetLongNameKey, assetDetails: assetDetails),
onEditPressed: () =>
_onEditPressed(key: assetLongNameKey, assetDetails: assetDetails),
),
_buildDivider(),
// asset icon display - can be edited
AssetIconDetails(
key: assetIconKey,
currIcon: assetDetails?.icon,
editingSectionOpened: editingAssetIcon,
onEditPressed: () => _onEditPressed(key: assetIconKey, assetDetails: assetDetails),
onEditPressed: () =>
_onEditPressed(key: assetIconKey, assetDetails: assetDetails),
),
_buildDivider(),
// asset issuer address display
Expand Down

0 comments on commit 6f871e5

Please sign in to comment.