Skip to content

Commit

Permalink
chore: 🚧 Adapt tx version 4
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Jan 8, 2025
1 parent 1efedbf commit 6666fd4
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 163 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ It supports the Archethic Cryptography rules which are:
#### setCode(code)
Add the code in the `data.code` section of the transaction
`code` is a string defining the smart contract
This method is available for transaction version <= 3

#### setContent(content)
Add the content in the `data.content` section of the transaction
Expand Down
1 change: 1 addition & 0 deletions lib/archethic_lib_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ library archethic;
export 'src/model/address.dart';
export 'src/model/authorized_key.dart';
export 'src/model/balance.dart';
export 'src/model/contract.dart';
export 'src/model/cross_validation_stamp.dart';
export 'src/model/crypto/aes_auth_encrypt_infos.dart';
export 'src/model/crypto/key_pair.dart';
Expand Down
41 changes: 41 additions & 0 deletions lib/src/model/contract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,45 @@ extension ContractUtils on Contract {
const Transaction(type: 'transfer')
.addRecipient(contractAddress, action: 'upgrade', args: [this]);
}

List<ContractAction> extractActionsFromContract(String code) {
final actions = <ContractAction>[];

final regex = RegExp(
r'actions\s+triggered_by:\s+transaction,\s+on:\s+([\w\s.,()]+?)\s+do',
);
final regexActionName = RegExp(r'(\w+)\((.*?)\)');

for (final match in regex.allMatches(code)) {
final fullAction = match.group(1) ?? '';

for (final actionMatch in regexActionName.allMatches(fullAction)) {
final name = actionMatch.group(1) ?? '';
final parameters = (actionMatch.group(2) ?? '').isNotEmpty
? actionMatch
.group(2)!
.split(',')
.map((param) => param.trim())
.toList()
: <String>[];
actions.add(
ContractAction(
name: name,
parameters: parameters,
),
);
}
}
return actions;
}

dynamic parseTypedArgument(dynamic input) {
if (input is Map) {
return input;
} else if (input is num || num.tryParse(input.toString()) != null) {
return double.tryParse(input.toString()) ?? input;
} else {
return input;
}
}
}
Loading

0 comments on commit 6666fd4

Please sign in to comment.