-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Stellar support #61
Closed
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3526fe0
Stellar dev
0bfd82d
add empty event for source_account in transactions
dca300f
Small fixes
Har01d e18165e
Use `operations` instead of `the-void` for dummy transfers
Har01d 9ac2a11
Set `ledger` as the entity name for blocks
Har01d 7f57f4d
Fix Stellar currency name
Har01d c2e7dd9
delete functionality that speeds up requests for transactions
cc0f428
Minor adjustments
Har01d e2f3f00
Fix tickers
Har01d b544551
fixes and add new transaction types
1ea0294
api_get* functions for transactions and addresses in Stellar
662c322
Stellar fix native currency and specials
8c7f742
merge with main
b4cd5df
add tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -656,6 +656,28 @@ MODULE_polygon-zkevm-erc-1155_NODES[]=http://login:[email protected]:1234/ | |
MODULE_polygon-zkevm-erc-1155_REQUESTER_TIMEOUT=60 | ||
MODULE_polygon-zkevm-erc-1155_REQUESTER_THREADS=12 | ||
|
||
##################### | ||
# Stellar Main Module | ||
##################### | ||
|
||
MODULES[]=stellar-main | ||
MODULE_stellar-main_CLASS=StellarMainModule | ||
MODULE_stellar-main_NODES[]=http://login:[email protected]:1234/ | ||
MODULE_stellar-main_NODES[]=http://login:[email protected]:1234/ | ||
MODULE_stellar-main_REQUESTER_TIMEOUT=60 | ||
MODULE_stellar-main_REQUESTER_THREADS=12 | ||
|
||
########################### | ||
# Stellar Operations Module | ||
########################### | ||
|
||
MODULES[]=stellar-operations | ||
MODULE_stellar-operations_CLASS=StellarOperationsModule | ||
MODULE_stellar-operations_NODES[]=http://login:[email protected]:1234/ | ||
MODULE_stellar-operations_NODES[]=http://login:[email protected]:1234/ | ||
MODULE_stellar-operations_REQUESTER_TIMEOUT=60 | ||
MODULE_stellar-operations_REQUESTER_THREADS=12 | ||
|
||
##################### | ||
## Ton Minimal Module | ||
##################### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
/* Idea (c) 2023 Nikita Zhavoronkov, [email protected] | ||
* Copyright (c) 2023-2024 3xpl developers, [email protected], see CONTRIBUTORS.md | ||
* Distributed under the MIT software license, see LICENSE.md */ | ||
|
||
/* This module processes main transactions in Stellar. Requires a Stellar node. */ | ||
|
||
abstract class StellarLikeMainModule extends CoreModule | ||
{ | ||
use StellarTraits; | ||
|
||
public ?BlockHashFormat $block_hash_format = BlockHashFormat::HexWithout0x; | ||
public ?AddressFormat $address_format = AddressFormat::AlphaNumeric; | ||
public ?TransactionHashFormat $transaction_hash_format = TransactionHashFormat::HexWithout0x; | ||
public ?TransactionRenderModel $transaction_render_model = TransactionRenderModel::Even; | ||
public ?CurrencyFormat $currency_format = CurrencyFormat::Static; | ||
public ?CurrencyType $currency_type = CurrencyType::FT; | ||
public ?FeeRenderModel $fee_render_model = FeeRenderModel::ExtraF; | ||
public ?array $special_addresses = ['the-void', 'operations']; | ||
public ?PrivacyModel $privacy_model = PrivacyModel::Transparent; | ||
|
||
public ?array $events_table_fields = ['block', 'transaction', 'sort_key', 'time', 'address', 'effect', 'failed', 'extra']; | ||
public ?array $events_table_nullable_fields = []; | ||
|
||
public ?ExtraDataModel $extra_data_model = ExtraDataModel::Default; | ||
public ?array $extra_data_details = null; | ||
|
||
public ?bool $should_return_events = true; | ||
public ?bool $should_return_currencies = false; | ||
public ?bool $allow_empty_return_events = true; | ||
public ?bool $allow_empty_return_currencies = false; | ||
|
||
public ?bool $mempool_implemented = false; | ||
public ?bool $forking_implemented = false; | ||
|
||
public string $block_entity_name = 'ledger'; | ||
|
||
// Blockchain-specific | ||
|
||
public ?int $transaction_count = null; | ||
public ?int $operation_count = null; | ||
public ?string $paging_token = null; | ||
|
||
// | ||
|
||
final public function pre_initialize() | ||
{ | ||
$this->version = 1; | ||
} | ||
|
||
|
||
final public function post_post_initialize() | ||
{ | ||
// | ||
} | ||
|
||
final public function pre_process_block($block_id) | ||
{ | ||
$events = []; | ||
$transactions = []; | ||
|
||
$transactions = $this->get_data_with_cursor( | ||
$this->select_node() . "ledgers/{$block_id}/transactions?order=desc&limit=%s&include_failed=true&cursor=%s", | ||
$this->transaction_count); | ||
|
||
$sort_key = 0; | ||
|
||
foreach ($transactions as $tx) | ||
{ | ||
$events[] = [ | ||
'transaction' => $tx['id'], | ||
'address' => $tx['fee_account'], | ||
'sort_key' => $sort_key++, | ||
'effect' => '-' . $tx['fee_charged'], | ||
'failed' => false, | ||
'extra' => 'f', | ||
]; | ||
|
||
$events[] = [ | ||
'transaction' => $tx['id'], | ||
'address' => 'the-void', | ||
'sort_key' => $sort_key++, | ||
'effect' => $tx['fee_charged'], | ||
'failed' => false, | ||
'extra' => 'f', | ||
]; | ||
|
||
$events[] = [ | ||
'transaction' => $tx['id'], | ||
'address' => $tx['source_account'], | ||
'sort_key' => $sort_key++, | ||
'effect' => '-0', | ||
'failed' => false, | ||
'extra' => 'o', // We need something different here | ||
]; | ||
|
||
$events[] = [ | ||
'transaction' => $tx['id'], | ||
'address' => 'operations', | ||
'sort_key' => $sort_key++, | ||
'effect' => '0', | ||
'failed' => false, | ||
'extra' => 'o', | ||
]; | ||
} | ||
|
||
//////////////// | ||
// Processing // | ||
//////////////// | ||
|
||
foreach ($events as &$event) | ||
{ | ||
$event['block'] = $block_id; | ||
$event['time'] = $this->block_time; | ||
} | ||
|
||
$this->set_return_events($events); | ||
} | ||
|
||
// Getting balances from the node | ||
public function api_get_balance($address) | ||
{ | ||
$account_balances = requester_single($this->select_node(), | ||
endpoint: "accounts/{$address}", | ||
result_in: 'balances', | ||
timeout: $this->timeout); | ||
|
||
foreach ($account_balances as $balance) | ||
{ | ||
if ($balance['asset_type'] === 'native') | ||
{ | ||
return $this->to_7($balance['balance']); | ||
} | ||
} | ||
|
||
throw new ModuleError('Unknown code flow'); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
extra_data_model
andextra_data_details
.