Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9736dc6
[7.x] drop @deprecated classes
rez1dent3 Nov 1, 2021
407d468
drop deprecated methods & Math,Lock-classes
rez1dent3 Nov 1, 2021
e2a7bbb
drop old logic
rez1dent3 Nov 1, 2021
42bfafb
[7.x] add uuid
rez1dent3 Nov 2, 2021
78f4a4e
[7.x] A lot of work on performance
rez1dent3 Nov 2, 2021
21fdc4a
ecs-fix
rez1dent3 Nov 2, 2021
11feda8
update config.php
rez1dent3 Nov 2, 2021
ad884c1
let's slow down a little
rez1dent3 Nov 2, 2021
4f4b0dd
add transfer dto
rez1dent3 Nov 2, 2021
c4a1559
update cart object
rez1dent3 Nov 3, 2021
90a644b
For a very long time, but I did it. Meet psalm
rez1dent3 Nov 3, 2021
1bc9dee
implement phpstan...
rez1dent3 Nov 3, 2021
f3417fd
drop @throws
rez1dent3 Nov 3, 2021
41c1ec2
update internal rules
rez1dent3 Nov 3, 2021
66f5fb6
non-empty-array
rez1dent3 Nov 3, 2021
a6b5b10
drop getUuid
rez1dent3 Nov 3, 2021
105864a
psalm
rez1dent3 Nov 4, 2021
b25d557
psalm
rez1dent3 Nov 4, 2021
9657a7c
add transaction dto
rez1dent3 Nov 4, 2021
9873efc
coverage
rez1dent3 Nov 4, 2021
0ddb8b5
update contracts
rez1dent3 Nov 4, 2021
735f93e
remove ConsistencyInterface from WalletService
rez1dent3 Nov 4, 2021
0dfb860
atm state
rez1dent3 Nov 4, 2021
9dfc35e
drop old code
rez1dent3 Nov 5, 2021
7f5daa1
fix filter bug
rez1dent3 Nov 5, 2021
165e939
drop Operation::class
rez1dent3 Nov 7, 2021
9f7c8cd
fix units
rez1dent3 Nov 7, 2021
fac092b
drop methods
rez1dent3 Nov 8, 2021
ab0db70
update common service
rez1dent3 Nov 8, 2021
4639164
fix repositories
rez1dent3 Nov 8, 2021
5f9bc3b
update addBalance method
rez1dent3 Nov 8, 2021
4f4a47a
add new unit
rez1dent3 Nov 8, 2021
ea9b80c
Trying to add lazy funds transfers
rez1dent3 Nov 8, 2021
a75e745
drop Bring object
rez1dent3 Nov 8, 2021
e15fec4
ecs parallel
rez1dent3 Nov 9, 2021
4bb35c4
update .phpstorm.meta.php
rez1dent3 Nov 9, 2021
e0a20eb
drop support casts in models
rez1dent3 Nov 9, 2021
890c189
removed unnecessary checks that are no longer needed
rez1dent3 Nov 9, 2021
c939181
update key
rez1dent3 Nov 10, 2021
50da224
drop units
rez1dent3 Nov 10, 2021
6442d00
fix ecs
rez1dent3 Nov 10, 2021
d914276
update BookkeeperService
rez1dent3 Nov 10, 2021
8bae070
- drop command
rez1dent3 Nov 10, 2021
9c800f2
update phpunits.yaml
rez1dent3 Nov 11, 2021
3f26829
update parallel
rez1dent3 Nov 11, 2021
aa96afc
return mariadb in phpunits.yaml
rez1dent3 Nov 11, 2021
659a761
transfer optimize
rez1dent3 Nov 11, 2021
336f8e0
update fee
rez1dent3 Nov 11, 2021
50562e4
optimize refundCart
rez1dent3 Nov 11, 2021
ba1fca3
optimize exchange
rez1dent3 Nov 11, 2021
31558a7
drop LockService::bindTo
rez1dent3 Nov 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.0

- name: Validate composer.json and composer.lock
run: composer validate --strict
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/phpunits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ jobs:

- name: Run test suite
run: |
if [[ $DB_CONNECTION == "testing" ]]; then
composer paraunit
else
if [[ $DB_CONNECTION == "mariadb" ]]; then
composer unit
else
composer parabench
fi
env:
CACHE_DRIVER: ${{ matrix.caches }}
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/psalm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: psalm

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
psalm:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run psalm
run: composer psalm
50 changes: 30 additions & 20 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,44 @@

namespace PHPSTORM_META {

use Bavix\Wallet\Interfaces\Mathable;
use Bavix\Wallet\Interfaces\Rateable;
use Bavix\Wallet\Interfaces\Storable;
use Bavix\Wallet\Models\Transaction;
use Bavix\Wallet\Models\Transfer;
use Bavix\Wallet\Models\Wallet;
use Bavix\Wallet\Objects\Bring;
use Bavix\Wallet\Internal\BasketInterface;
use Bavix\Wallet\Internal\BookkeeperInterface;
use Bavix\Wallet\Internal\CartInterface;
use Bavix\Wallet\Internal\ConsistencyInterface;
use Bavix\Wallet\Internal\ExchangeInterface;
use Bavix\Wallet\Internal\LockInterface;
use Bavix\Wallet\Internal\MathInterface;
use Bavix\Wallet\Internal\PurchaseInterface;
use Bavix\Wallet\Internal\StorageInterface;
use Bavix\Wallet\Internal\UuidInterface;
use Bavix\Wallet\Objects\Cart;
use Bavix\Wallet\Objects\EmptyLock;
use Bavix\Wallet\Objects\Operation;
use Bavix\Wallet\Services\CommonService;
use Bavix\Wallet\Services\ExchangeService;
use Bavix\Wallet\Services\DbService;
use Bavix\Wallet\Services\LockService;
use Bavix\Wallet\Services\MetaService;
use Bavix\Wallet\Services\WalletService;

override(\app(0), map([
BasketInterface::class => BasketInterface::class,
BookkeeperInterface::class => BookkeeperInterface::class,
CartInterface::class => CartInterface::class,
ConsistencyInterface::class => ConsistencyInterface::class,
ExchangeInterface::class => ExchangeInterface::class,
LockInterface::class => LockInterface::class,
MathInterface::class => MathInterface::class,
PurchaseInterface::class => PurchaseInterface::class,
StorageInterface::class => StorageInterface::class,
UuidInterface::class => UuidInterface::class,

// deprecated's
Cart::class => Cart::class,
Bring::class => Bring::class,
Operation::class => Operation::class,
EmptyLock::class => EmptyLock::class,
ExchangeService::class => ExchangeService::class,

// old
CommonService::class => CommonService::class,
DbService::class => DbService::class,
LockService::class => LockService::class,
MetaService::class => MetaService::class,
WalletService::class => WalletService::class,
Wallet::class => Wallet::class,
Transfer::class => Transfer::class,
Transaction::class => Transaction::class,
Mathable::class => Mathable::class,
Rateable::class => Rateable::class,
Storable::class => Storable::class,
]));

}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"illuminate/database": "^6.0|^7.0|^8.0",
"doctrine/dbal": "^2.8|^3.0",
"ramsey/uuid": "^3.0|^4.0",
"brick/math": "~0.8"
"brick/math": "~0.8",
"ext-json": "*"
},
"require-dev": {
"brianium/paratest": "^6.2",
Expand Down
111 changes: 31 additions & 80 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -1,120 +1,71 @@
<?php

declare(strict_types=1);

use Bavix\Wallet\Models\Transaction;
use Bavix\Wallet\Models\Transfer;
use Bavix\Wallet\Models\Wallet;
use Bavix\Wallet\Objects\Bring;
use Bavix\Wallet\Objects\Cart;
use Bavix\Wallet\Objects\EmptyLock;
use Bavix\Wallet\Objects\Operation;
use Bavix\Wallet\Services\AtomicService;
use Bavix\Wallet\Services\BasketService;
use Bavix\Wallet\Services\BookkeeperService;
use Bavix\Wallet\Services\CommonService;
use Bavix\Wallet\Services\ConsistencyService;
use Bavix\Wallet\Services\DbService;
use Bavix\Wallet\Services\ExchangeService;
use Bavix\Wallet\Services\LockService;
use Bavix\Wallet\Services\MathService;
use Bavix\Wallet\Services\MetaService;
use Bavix\Wallet\Services\PurchaseService;
use Bavix\Wallet\Services\StorageService;
use Bavix\Wallet\Services\UuidFactoryService;
use Bavix\Wallet\Services\WalletService;
use Bavix\Wallet\Simple\Exchange;
use Bavix\Wallet\Simple\Rate;
use Bavix\Wallet\Simple\Store;

return [
/**
* This parameter is necessary for more accurate calculations.
* PS, Arbitrary Precision Calculations.
*/
'math' => [
'scale' => 64,
],

/**
* The parameter is used for fast packet overload.
* You do not need to search for the desired class by code, the library will do it itself.
*/
'package' => [
'exchange' => Exchange::class,
'rateable' => Rate::class,
'storable' => Store::class,
'mathable' => MathService::class,
],

/**
* Lock settings for highload projects.
*
* If you want to replace the default cache with another,
* then write the name of the driver cache in the key `wallet.lock.cache`.
* @see https://laravel.com/docs/6.x/cache#driver-prerequisites
*
* @example
* 'cache' => 'redis'
*/
// infra settings
'cache' => ['driver' => null],
'lock' => [
'cache' => null,
'enabled' => false,
'driver' => null,
'seconds' => 1,
],

/**
* Sometimes a slug may not match the currency and you need the ability to add an exception.
* The main thing is that there are not many exceptions).
*
* Syntax:
* 'slug' => 'currency'
*
* @example
* 'my-usd' => 'USD'
*
* @deprecated use table "wallets", column meta.currency
*/
'currencies' => [],
// long arithmetic
'math' => ['scale' => 64],

/**
* Services are the main core of the library and sometimes they need to be improved.
* This configuration will help you to quickly customize the library.
*/
// service overload
'services' => [
'basket' => BasketService::class,
'bookkeeper' => BookkeeperService::class,
'consistency' => ConsistencyService::class,
'exchange' => ExchangeService::class,
'atomic' => AtomicService::class,
'math' => MathService::class,
'purchase' => PurchaseService::class,
'storage' => StorageService::class,
'uuid' => UuidFactoryService::class,
],

// legacy-service overload
'legacy' => [
'common' => CommonService::class,
'wallet' => WalletService::class,
'db' => DbService::class,
'lock' => LockService::class,
'meta' => MetaService::class,
],

'objects' => [
'bring' => Bring::class,
'cart' => Cart::class,
'emptyLock' => EmptyLock::class,
'operation' => Operation::class,
],

/**
* Transaction model configuration.
*/
'transaction' => [
'table' => 'transactions',
'model' => Transaction::class,
'casts' => [
'amount' => 'string',
],
],

/**
* Transfer model configuration.
*/
'transfer' => [
'table' => 'transfers',
'model' => Transfer::class,
'casts' => [
'fee' => 'string',
],
],

/**
* Wallet model configuration.
*/
'wallet' => [
'table' => 'wallets',
'model' => Wallet::class,
'casts' => [
'balance' => 'string',
],
'creating' => [],
'default' => [
'name' => 'Default Wallet',
Expand Down
1 change: 1 addition & 0 deletions database/2018_11_15_124230_create_wallets_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function up(): void
$table->morphs('holder');
$table->string('name');
$table->string('slug')->index();
$table->uuid('uuid')->unique();
$table->string('description')->nullable();
$table->json('meta')->nullable();
$table->decimal('balance', 64, 0)->default(0);
Expand Down
50 changes: 50 additions & 0 deletions database/2021_11_02_202021_update_wallets_uuid_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

use Bavix\Wallet\Internal\UuidInterface;
use Bavix\Wallet\Models\Wallet;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Schema;

class UpdateWalletsUuidTable extends Migration
{
public function up(): void
{
if (Schema::hasColumn($this->table(), 'uuid')) {
return;
}

// upgrade from 6.x
Schema::table($this->table(), function (Blueprint $table) {
$table->uuid('uuid')
->after('slug')
->nullable()
->unique()
;
});

Wallet::query()->chunk(10000, static function (Collection $wallets) {
$wallets->each(function (Wallet $wallet) {
$wallet->uuid = app(UuidInterface::class)->uuid4();
$wallet->save();
});
});

Schema::table($this->table(), static function (Blueprint $table) {
$table->uuid('uuid')->change();
});
}

public function down(): void
{
Schema::dropColumns($this->table(), ['uuid']);
}

protected function table(): string
{
return (new Wallet())->getTable();
}
}
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
//$services->set(DeclareStrictTypesFixer::class);

$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PARALLEL, true);
$parameters->set(Option::PATHS, [
__DIR__ . '/config',
__DIR__ . '/database',
__DIR__ . '/resources/lang',
__DIR__ . '/src',
__DIR__ . '/tests',
]);
Expand Down
34 changes: 0 additions & 34 deletions src/Commands/RefreshBalance.php

This file was deleted.

Loading