mempool weather added

This commit is contained in:
HolgerHatGarKeineNode
2023-03-31 15:54:11 +02:00
parent 876c69ba5c
commit 4bca05b998
9 changed files with 528 additions and 8 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Console\Commands\MempoolSpace;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
class CacheRecommendedFees extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'mempool:recommended-fees';
/**
* The console command description.
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle(): void
{
$apiKey = config('services.open-ai.apiKey');
$client = OpenAI::client($apiKey);
$result = Http::get('https://mempool.space/api/v1/fees/recommended');
$result = $result->json();
$result = $client->completions()
->create([
'model' => 'text-davinci-003',
'prompt' => sprintf('Erstelle einen Wetterbericht für den Bitcoin Mempool mit folgenden Gebühren: fastestFee: %s sat/vB, halfHourFee: %s sat/vB, hourFee: %s sat/vB, economyFee: %s sat/vB, minimumFee: %s sat/vB. Fasse mit maximal 400 Zeichen zusammen und schreibe im Stile eines Wetterberichtes aus dem Fernsehen um.',
$result['fastestFee'],
$result['halfHourFee'],
$result['hourFee'],
$result['economyFee'],
$result['minimumFee']
),
'max_tokens' => 400,
'temperature' => 1
]);
cache()->put('mempool-weather', $result['choices'][0]['text'], now()->addMinutes(62));
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
use OpenAI;
class Test extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'test';
/**
* The console command description.
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle(): void
{
$apiKey = config('services.open-ai.apiKey');
$client = OpenAI::client($apiKey);
$result = Http::get('https://mempool.space/api/v1/fees/recommended');
$result = $result->json();
$result = $client->completions()
->create([
'model' => 'text-davinci-003',
'prompt' => sprintf('Erstelle einen Wetterbericht für den Bitcoin Mempool mit folgenden Gebühren: fastestFee: %s sat/vB, halfHourFee: %s sat/vB, hourFee: %s sat/vB, economyFee: %s sat/vB, minimumFee: %s sat/vB. Fasse mit maximal 400 Zeichen zusammen und schreibe im Stile eines Wetterberichtes aus dem Fernsehen um.',
$result['fastestFee'],
$result['halfHourFee'],
$result['hourFee'],
$result['economyFee'],
$result['minimumFee']
),
'max_tokens' => 400,
'temperature' => 1
]);
cache()->put('mempool-weather', $result['choices'][0]['text'], now()->addMinutes(60));
}
}

View File

@@ -4,6 +4,7 @@ namespace App\Console;
use App\Console\Commands\Database\CleanupLoginKeys; use App\Console\Commands\Database\CleanupLoginKeys;
use App\Console\Commands\Feed\ReadAndSyncPodcastFeeds; use App\Console\Commands\Feed\ReadAndSyncPodcastFeeds;
use App\Console\Commands\MempoolSpace\CacheRecommendedFees;
use App\Console\Commands\Nostr\PublishUnpublishedItems; use App\Console\Commands\Nostr\PublishUnpublishedItems;
use App\Console\Commands\OpenBooks\SyncOpenBooks; use App\Console\Commands\OpenBooks\SyncOpenBooks;
use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\Schedule;
@@ -22,6 +23,7 @@ class Kernel extends ConsoleKernel
*/ */
protected function schedule(Schedule $schedule): void protected function schedule(Schedule $schedule): void
{ {
$schedule->command(CacheRecommendedFees::class)->hourly();
$schedule->call(new PruneStaleAttachments) $schedule->call(new PruneStaleAttachments)
->daily(); ->daily();
$schedule->command(SyncOpenBooks::class) $schedule->command(SyncOpenBooks::class)

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Livewire\Banner;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Http;
use Livewire\Component;
class MempoolWeather extends Component
{
public string $weather = '';
public $fastestFee;
public $halfHourFee;
public $hourFee;
public $economyFee;
public $minimumFee;
public function mount()
{
if (cache()->has('mempool-weather')) {
$this->weather = cache()->get('mempool-weather');
} else {
Artisan::call('test');
$this->weather = cache()->get('mempool-weather');
}
$result = Http::get('https://mempool.space/api/v1/fees/recommended');
$result = $result->json();
$this->fastestFee = $result['fastestFee'];
$this->halfHourFee = $result['halfHourFee'];
$this->hourFee = $result['hourFee'];
$this->economyFee = $result['economyFee'];
$this->minimumFee = $result['minimumFee'];
}
public function render()
{
return view('livewire.banner.mempool-weather');
}
}

View File

@@ -32,6 +32,7 @@
"maatwebsite/excel": "^3.1", "maatwebsite/excel": "^3.1",
"nova/start": "*", "nova/start": "*",
"oneduo/nova-time-field": "^1.0", "oneduo/nova-time-field": "^1.0",
"openai-php/client": "^0.4.1",
"podcastindex/podcastindex-php": "^1.0", "podcastindex/podcastindex-php": "^1.0",
"pusher/pusher-php-server": "^7.2.2", "pusher/pusher-php-server": "^7.2.2",
"qcod/laravel-gamify": "dev-master#6c0a55cf5351be5e7b4f31aa2499984853d895cf", "qcod/laravel-gamify": "dev-master#6c0a55cf5351be5e7b4f31aa2499984853d895cf",

154
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "10cbc0cb01e1977c4c976223bd697558", "content-hash": "b2f000a7c7d14f41df877996099dbe51",
"packages": [ "packages": [
{ {
"name": "akuechler/laravel-geoly", "name": "akuechler/laravel-geoly",
@@ -5853,6 +5853,96 @@
}, },
"time": "2022-11-18T17:20:22+00:00" "time": "2022-11-18T17:20:22+00:00"
}, },
{
"name": "openai-php/client",
"version": "v0.4.1",
"source": {
"type": "git",
"url": "https://github.com/openai-php/client.git",
"reference": "b16dbad9ac6507f7d9a3ec365b906f659e50e2b9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/openai-php/client/zipball/b16dbad9ac6507f7d9a3ec365b906f659e50e2b9",
"reference": "b16dbad9ac6507f7d9a3ec365b906f659e50e2b9",
"shasum": ""
},
"require": {
"php": "^8.1.0",
"php-http/discovery": "^1.15.2",
"php-http/multipart-stream-builder": "^1.2.0",
"psr/http-client": "^1.0.1",
"psr/http-client-implementation": "^1.0.1",
"psr/http-factory-implementation": "*",
"psr/http-message": "^1.0.1"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.5.0",
"laravel/pint": "^1.7.0",
"nunomaduro/collision": "^7.3.3",
"pestphp/pest": "^2.2.3",
"pestphp/pest-plugin-arch": "^2.0.2",
"pestphp/pest-plugin-mock": "^2.0.0",
"phpstan/phpstan": "^1.10.8",
"rector/rector": "^0.14.8",
"symfony/var-dumper": "^6.2.7"
},
"type": "library",
"autoload": {
"files": [
"src/OpenAI.php"
],
"psr-4": {
"OpenAI\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nuno Maduro",
"email": "enunomaduro@gmail.com"
},
{
"name": "Sandro Gehri"
}
],
"description": "OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API",
"keywords": [
"GPT-3",
"api",
"client",
"codex",
"dall-e",
"language",
"natural",
"openai",
"php",
"processing",
"sdk"
],
"support": {
"issues": "https://github.com/openai-php/client/issues",
"source": "https://github.com/openai-php/client/tree/v0.4.1"
},
"funding": [
{
"url": "https://www.paypal.com/paypalme/enunomaduro",
"type": "custom"
},
{
"url": "https://github.com/gehrisandro",
"type": "github"
},
{
"url": "https://github.com/nunomaduro",
"type": "github"
}
],
"time": "2023-03-24T11:41:32+00:00"
},
{ {
"name": "openspout/openspout", "name": "openspout/openspout",
"version": "v4.13.0", "version": "v4.13.0",
@@ -6549,6 +6639,68 @@
}, },
"time": "2015-12-19T14:08:53+00:00" "time": "2015-12-19T14:08:53+00:00"
}, },
{
"name": "php-http/multipart-stream-builder",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/php-http/multipart-stream-builder.git",
"reference": "11c1d31f72e01c738bbce9e27649a7cca829c30e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-http/multipart-stream-builder/zipball/11c1d31f72e01c738bbce9e27649a7cca829c30e",
"reference": "11c1d31f72e01c738bbce9e27649a7cca829c30e",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0",
"php-http/discovery": "^1.7",
"php-http/message-factory": "^1.0.2",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"nyholm/psr7": "^1.0",
"php-http/message": "^1.5",
"phpunit/phpunit": "^7.5.15 || ^8.5 || ^9.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Http\\Message\\MultipartStream\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com"
}
],
"description": "A builder class that help you create a multipart stream",
"homepage": "http://php-http.org",
"keywords": [
"factory",
"http",
"message",
"multipart stream",
"stream"
],
"support": {
"issues": "https://github.com/php-http/multipart-stream-builder/issues",
"source": "https://github.com/php-http/multipart-stream-builder/tree/1.2.0"
},
"time": "2021-05-21T08:32:01+00:00"
},
{ {
"name": "php-http/promise", "name": "php-http/promise",
"version": "1.1.0", "version": "1.1.0",

View File

@@ -2,6 +2,10 @@
return [ return [
'open-ai' => [
'apiKey' => env('OPEN_AI_API_KEY'),
],
'horizon' => [ 'horizon' => [
'secret' => env('HORIZON_SECRET'), 'secret' => env('HORIZON_SECRET'),
], ],
@@ -19,10 +23,10 @@ return [
*/ */
'mailgun' => [ 'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'), 'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'), 'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
'scheme' => 'https', 'scheme' => 'https',
], ],
'postmark' => [ 'postmark' => [
@@ -30,16 +34,16 @@ return [
], ],
'ses' => [ 'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'), 'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'), 'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
], ],
'twitter' => [ 'twitter' => [
'oauth' => 2, 'oauth' => 2,
'client_id' => env('TWITTER_CLIENT_ID'), 'client_id' => env('TWITTER_CLIENT_ID'),
'client_secret' => env('TWITTER_CLIENT_SECRET'), 'client_secret' => env('TWITTER_CLIENT_SECRET'),
'redirect' => env('TWITTER_REDIRECT_URI'), 'redirect' => env('TWITTER_REDIRECT_URI'),
], ],
]; ];

View File

@@ -0,0 +1,220 @@
<div
class="relative isolate flex items-center justify-center gap-x-6 overflow-hidden bg-gray-50 px-6 py-2.5 sm:px-3.5 sm:before:flex-1">
<div class="absolute left-[max(-7rem,calc(50%-52rem))] top-1/2 -z-10 -translate-y-1/2 transform-gpu blur-2xl"
aria-hidden="true">
<div class="aspect-[577/310] w-[36.0625rem] bg-gradient-to-r from-[#FABE75] to-[#F7931A] opacity-30"
style="clip-path: polygon(74.8% 41.9%, 97.2% 73.2%, 100% 34.9%, 92.5% 0.4%, 87.5% 0%, 75% 28.6%, 58.5% 54.6%, 50.1% 56.8%, 46.9% 44%, 48.3% 17.4%, 24.7% 53.9%, 0% 27.9%, 11.9% 74.2%, 24.9% 54.1%, 68.6% 100%, 74.8% 41.9%)"></div>
</div>
<div class="absolute left-[max(45rem,calc(50%+8rem))] top-1/2 -z-10 -translate-y-1/2 transform-gpu blur-2xl"
aria-hidden="true">
<div class="aspect-[577/310] w-[36.0625rem] bg-gradient-to-r from-[#FABE75] to-[#F7931A] opacity-30"
style="clip-path: polygon(74.8% 41.9%, 97.2% 73.2%, 100% 34.9%, 92.5% 0.4%, 87.5% 0%, 75% 28.6%, 58.5% 54.6%, 50.1% 56.8%, 46.9% 44%, 48.3% 17.4%, 24.7% 53.9%, 0% 27.9%, 11.9% 74.2%, 24.9% 54.1%, 68.6% 100%, 74.8% 41.9%)"></div>
</div>
<div class="w-full flex flex-col sm:flex-row justify-center">
<div class="text-md leading-6 text-gray-900 text-center max-w-screen-2xl">
{{ $weather }}
</div>
<div>
<div
_ngcontent-serverapp-c131=""
class="flex flex-col justify-around p-5 leading-6 text-center text-white break-words"
style="min-height: 1px; list-style: outside;"
>
<app-fees-box
_ngcontent-serverapp-c131=""
class="block text-center break-words"
_nghost-serverapp-c126=""
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="text-white"
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="flex break-words"
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="flex flex-row mb-3 w-1/4 h-5 bg-lime-700"
style="background: rgb(93, 125, 1); --darkreader-inline-bgcolor: #4a6401; --darkreader-inline-bgimage: none; transition: background-color 1s ease 0s; list-style: outside;"
data-darkreader-inline-bgcolor=""
data-darkreader-inline-bgimage=""
>
<span
_ngcontent-serverapp-c126=""
ngbtooltip="Either 2x the minimum, or the Low Priority rate (whichever is lower)"
placement="top"
class="px-1 pt-px w-full text-xs leading-4 truncate"
style="list-style: outside;"
>No Priority</span>
</div>
<div
_ngcontent-serverapp-c126=""
class="h-5 bg-white bg-opacity-[0]"
style="width: 4%; background-image: repeating-linear-gradient(90deg, rgb(36, 41, 58), rgb(36, 41, 58) 2px, rgb(23, 25, 39) 2px, rgb(23, 25, 39) 4px); list-style: outside;"
></div>
<div
_ngcontent-serverapp-c126=""
class="flex flex-row mb-3 w-3/4 h-5"
style="background: linear-gradient(to right, rgb(93, 125, 1), rgb(166, 125, 14)); --darkreader-inline-bgcolor: rgba(0, 0, 0, 0); --darkreader-inline-bgimage: linear-gradient(to right, #4a6401, #85640b); transition: background-color 1s ease 0s; border-radius: 0px 10px 10px 0px; list-style: outside;"
data-darkreader-inline-bgcolor=""
data-darkreader-inline-bgimage=""
>
<span
_ngcontent-serverapp-c126=""
ngbtooltip="Usually places your transaction in between the second and third mempool blocks"
placement="top"
class="px-1 pt-px w-1/3 text-xs leading-4 truncate"
style="list-style: outside;"
>Hour</span><span
_ngcontent-serverapp-c126=""
ngbtooltip="Usually places your transaction in between the first and second mempool blocks"
placement="top"
class="px-1 pt-px w-1/3 text-xs leading-4 truncate"
style="list-style: outside;"
>Half Hour</span
><span
_ngcontent-serverapp-c126=""
ngbtooltip="Places your transaction in the first mempool block"
placement="top"
class="px-1 pt-px w-1/3 text-xs leading-4 truncate"
style="list-style: outside;"
>Fastest</span
>
</div>
</div>
<div
_ngcontent-serverapp-c126=""
class="flex flex-row justify-between break-words"
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="my-0 mx-auto w-24"
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="mb-0 text-xl leading-8"
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="m-auto leading-7 border-b border-gray-200 border-solid text-gray-900"
style="list-style: outside;"
>
{{ $minimumFee }}
<span
_ngcontent-serverapp-c126=""
class="inline-flex relative top-0 text-xs leading-4 text-gray-900"
style="list-style: outside;"
>sat/vB</span
>
</div>
</div>
</div>
<div
_ngcontent-serverapp-c126=""
class=""
style="width: 4%; list-style: outside;"
></div>
<div
_ngcontent-serverapp-c126=""
class="my-0 mx-auto w-24"
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="mb-0 text-xl leading-8"
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="m-auto leading-7 border-b border-gray-200 border-solid text-gray-900"
style="list-style: outside;"
>
{{ $hourFee }}
<span
_ngcontent-serverapp-c126=""
class="inline-flex relative top-0 text-xs leading-4 text-gray-900"
style="list-style: outside;"
>sat/vB</span>
</div>
<span
_ngcontent-serverapp-c126=""
class="block relative top-0 text-xs leading-5 text-gray-900"
style="list-style: outside;"
></span>
</div>
</div>
<div
_ngcontent-serverapp-c126=""
class="my-0 mx-auto w-24"
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="mb-0 text-xl leading-8"
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="m-auto leading-7 border-b border-gray-200 border-solid text-gray-900"
style="list-style: outside;"
>
{{ $halfHourFee }}
<span
_ngcontent-serverapp-c126=""
class="inline-flex relative top-0 text-xs leading-4 text-gray-900"
style="list-style: outside;"
>sat/vB</span
>
</div>
<span
_ngcontent-serverapp-c126=""
class="block relative top-0 text-xs leading-5 text-gray-900"
style="list-style: outside;"
></span>
</div>
</div>
<div
_ngcontent-serverapp-c126=""
class="my-0 mx-auto w-24"
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="mb-0 text-xl leading-8"
style="list-style: outside;"
>
<div
_ngcontent-serverapp-c126=""
class="m-auto leading-7 border-b border-gray-200 border-solid text-gray-900"
style="list-style: outside;"
>
{{ $fastestFee }}
<span
_ngcontent-serverapp-c126=""
class="inline-flex relative top-0 text-xs leading-4 text-gray-900"
style="list-style: outside;"
>sat/vB</span
>
</div>
<span
_ngcontent-serverapp-c126=""
class="block relative top-0 text-xs leading-5 text-gray-900"
style="list-style: outside;"
></span>
</div>
</div>
</div>
</div>
</app-fees-box>
</div>
</div>
</div>
</div>

View File

@@ -4,6 +4,8 @@
@endpush @endpush
<livewire:frontend.header :country="null"/> <livewire:frontend.header :country="null"/>
<livewire:banner.mempool-weather/>
<div class="relative bg-21gray px-6 pt-2 pb-20 lg:px-8 lg:pt-2 lg:pb-2"> <div class="relative bg-21gray px-6 pt-2 pb-20 lg:px-8 lg:pt-2 lg:pb-2">
<div class="absolute inset-0"> <div class="absolute inset-0">
<div class="h-1/3 bg-21gray sm:h-2/3"></div> <div class="h-1/3 bg-21gray sm:h-2/3"></div>