-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
442 additions
and
27 deletions.
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Deploy Demo to GitHub Pages | ||
|
||
on: | ||
push: | ||
branches: ["master"] | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Delete demo/pkg symlink | ||
run: rm -fr demo/pkg | ||
|
||
- name: Setup Rust Toolchain | ||
uses: actions-rust-lang/setup-rust@v1 | ||
with: | ||
toolchain: stable | ||
target: wasm32-unknown-unknown | ||
|
||
- name: Install wasm-pack | ||
uses: qmaru/[email protected] | ||
with: | ||
version: '0.11.1' | ||
|
||
- name: Build Rust Miner | ||
run: | | ||
bash ./scripts/build-notemine-wasm.sh | ||
# - name: Setup Node.js | ||
# uses: actions/setup-node@v3 | ||
# with: | ||
# node-version: '20' | ||
|
||
- name: Install Dependencies | ||
run: yarn install | ||
|
||
- name: Build with Webpack | ||
run: yarn build |
Empty file.
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,32 @@ | ||
name: Deploy Demo to GitHub Pages | ||
|
||
on: | ||
push: | ||
branches: ["master"] | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install | ||
run: yarn install | ||
|
||
- name: Webpack | ||
run: yarn build | ||
|
||
- name: Vitest | ||
run: yarn test |
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 |
---|---|---|
@@ -1,4 +1,305 @@ | ||
# notemine js | ||
|
||
![build](https://img.shields.io/npm/v/notemine) | ||
![build](https://github.com/github/docs/actions/workflows/main.yml/badge.svg) | ||
![test](https://github.com/github/docs/actions/workflows/main.yml/badge.svg) | ||
![coverage](https://github.com/github/docs/actions/workflows/main.yml/badge.svg) | ||
|
||
a module for implementing [notemine](https://github.com/sandwichfarm/notemine) wasm nostr event miner in modern web applications with observables. | ||
|
||
## install | ||
package name: `notemine` | ||
|
||
**npm** | ||
```bash | ||
npm install notemine | ||
``` | ||
|
||
<details> | ||
<summary>pnpm</summary> | ||
|
||
```bash | ||
pnpm install notemine | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>yarn</summary> | ||
|
||
```bash | ||
yarn install notemine | ||
``` | ||
</details> | ||
|
||
## usage | ||
_untested_ | ||
|
||
```typescript | ||
import Notemine from "notemine" | ||
|
||
//prepare meta for event | ||
const content = "hello world." | ||
const tags = [ "#t", "introduction"] | ||
const pubkey = "e771af0b05c8e95fcdf6feb3500544d2fb1ccd384788e9f490bb3ee28e8ed66f" | ||
|
||
//set options for miner | ||
const difficulty = 21 | ||
const numberOfWorkers = 7 | ||
|
||
|
||
const noteminer = new Noteminer({ | ||
content, | ||
tags, | ||
difficulty, | ||
numberOfWorkers | ||
}) | ||
|
||
//you can also set content, tags and pubkey via assessors after initialization. | ||
noteminer.pubkey = pubkey | ||
|
||
//start miner | ||
noteminer.mine() | ||
``` | ||
|
||
Updates to noteminer can be accessed via observables. | ||
``` | ||
noteminer.progress$ | ||
noteminer.error$ | ||
noteminer.progress$ | ||
noteminer.progress$ | ||
``` | ||
|
||
|
||
|
||
<details> | ||
<summary>svelte</summary> | ||
|
||
```svelte | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
import { type Writable, writable } from 'svelte/store' | ||
import { type ProgressEvent, NostrMiner } from 'nostr-miner'; | ||
const numberOfMiners = 8 | ||
let miner: NostrMiner; | ||
let progress: Writable<ProgressEvent[]> = new writable(new Array(numberOfMiners)) | ||
onMount(() => { | ||
miner = new NostrMiner({ content: 'Hello, Nostr!', numberOfMiners }); | ||
const subscription = miner.progress$.subscribe(progress_ => { | ||
progress.update( _progress => { | ||
_progress[progress_.workerId] = progress_ | ||
}) | ||
}); | ||
miner.mine(); | ||
return () => { | ||
subscription.unsubscribe(); | ||
miner.cancel(); | ||
}; | ||
}); | ||
$: miners = $progress | ||
</script> | ||
<div> | ||
{#each $miners as miner} | ||
<span>Miner #{miner.workerId}: {miner.hashRate}kH/s [Best PoW: ${miner.bestPowData}] | ||
{/each} | ||
</div> | ||
``` | ||
</details> | ||
|
||
|
||
|
||
<details> | ||
<summary>react</summary> | ||
|
||
```reactjs | ||
import React, { useEffect } from 'react'; | ||
import { NostrMiner } from 'nostr-miner'; | ||
const MyComponent = () => { | ||
const miner = new NostrMiner({ content: 'Hello, Nostr!' }); | ||
useEffect(() => { | ||
const subscription = miner.progress$.subscribe(progress => { | ||
// Update progress bar or display miner's progress | ||
}); | ||
miner.mine(); | ||
return () => { | ||
subscription.unsubscribe(); | ||
miner.cancel(); | ||
}; | ||
}, []); | ||
return ( | ||
<div> | ||
{/* Your UI components */} | ||
</div> | ||
); | ||
}; | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>vue</summary> | ||
|
||
```vue | ||
<template> | ||
<div> | ||
<!-- Your UI components --> | ||
</div> | ||
</template> | ||
<script lang="ts"> | ||
import { defineComponent, onMounted, onUnmounted } from 'vue'; | ||
import { NostrMiner } from 'nostr-miner'; | ||
export default defineComponent({ | ||
name: 'MinerComponent', | ||
setup() { | ||
const miner = new NostrMiner({ content: 'Hello, Nostr!' }); | ||
onMounted(() => { | ||
const subscription = miner.progress$.subscribe(progress => { | ||
// Update progress bar or display miner's progress | ||
}); | ||
miner.mine(); | ||
onUnmounted(() => { | ||
subscription.unsubscribe(); | ||
miner.cancel(); | ||
}); | ||
}); | ||
return {}; | ||
}, | ||
}); | ||
</script> | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>angular</summary> | ||
|
||
```javascript | ||
import { Component, OnInit, OnDestroy } from '@angular/core'; | ||
import { NostrMiner } from 'nostr-miner'; | ||
import { Subscription } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'app-miner', | ||
templateUrl: './miner.component.html', | ||
}) | ||
export class MinerComponent implements OnInit, OnDestroy { | ||
miner: NostrMiner; | ||
progressSubscription: Subscription; | ||
|
||
ngOnInit() { | ||
this.miner = new NostrMiner({ content: 'Hello, Nostr!' }); | ||
this.progressSubscription = this.miner.progress$.subscribe(progress => { | ||
// Update progress bar or display miner's progress | ||
}); | ||
|
||
this.miner.mine(); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.progressSubscription.unsubscribe(); | ||
this.miner.cancel(); | ||
} | ||
} | ||
``` | ||
</details> | ||
|
||
## build | ||
The wasm is not included in version control, so to build you'll need rust and it's toolchain. That includes `rustup` and `cargo` | ||
|
||
### install build deps | ||
|
||
Install **wasm-pack** with `cargo install wasm-pack` | ||
|
||
### build wasm | ||
Build the wasm with `build:wasm` | ||
|
||
**npm** | ||
|
||
```bash | ||
npm build:wasm | ||
``` | ||
|
||
<details> | ||
<summary>pnpm</summary> | ||
|
||
```bash | ||
pnpm build:wasm | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>yarn</summary> | ||
|
||
```bash | ||
yarn build:wasm | ||
``` | ||
</details> | ||
|
||
### build package | ||
|
||
Build the package with `build` | ||
**npm** | ||
|
||
```bash | ||
npm run build | ||
``` | ||
|
||
<details> | ||
<summary>pnpm</summary> | ||
|
||
```bash | ||
pnpm run build | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>yarn</summary> | ||
|
||
```bash | ||
yarn build | ||
``` | ||
</details> | ||
|
||
### test | ||
<details> | ||
<summary>npm</summary> | ||
|
||
```bash | ||
npm run build | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>pnpm</summary> | ||
|
||
```bash | ||
pnpm run build | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>yarn</summary> | ||
|
||
```bash | ||
yarn build | ||
``` | ||
</details> |
Oops, something went wrong.