Skip to content

Commit

Permalink
add some anarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
gandlafbtc committed Feb 18, 2023
1 parent daa6477 commit 4f60d4c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PORT=3000
MINT_URL='https://legend.lnbits.com/cashu/api/v1/4gr9Xcmz3XEkUNwiBiQGoC'
FAUCET_INTERVAL=10000
SATS_PER_INTERVAL=10
FAUCET_INTERVAL=5000
SATS_PER_INTERVAL=1
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "gandlaf21",
"license": "ISC",
"dependencies": {
"@gandlaf21/cashu-tools": "^0.1.4",
"@gandlaf21/cashu-tools": "^0.1.5",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
Expand Down
17 changes: 7 additions & 10 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('dotenv').config()

const { CashuMint, CashuWallet, getEncodedProofs } = require("@gandlaf21/cashu-ts")
const { Faucet, utils } = require ("@gandlaf21/cashu-tools")
const { getEncodedProofs } = require("@gandlaf21/cashu-ts")
const { AnarchoFaucet , utils } = require ("@gandlaf21/cashu-tools")
const rateLimit = require('express-rate-limit')
const cors = require('cors');

Expand All @@ -23,29 +23,26 @@ app.use(cors());

app.get('/', (req, res) => {
let responseString ="Token has already been claimed! waiting for next token..."
if(faucet.currentToken.length>0){
if(faucet.currentToken){
responseString =
getEncodedProofs(faucet.currentToken ,[{url:process.env.MINT_URL, keysets: [...new Set(faucet.currentToken.map(t=>t.id))]}])
getEncodedProofs(faucet.currentToken.proofs ,faucet.currentToken.mints)
}
res.send({token: responseString})
})

app.get('/balance', async (req, res) => {
res.send({remaining: utils.getAmountForTokenSet(faucet.balance)})
res.send({remaining: utils.getAmountForTokenSet(faucet.balance),
mintCount: faucet.wallets.length})
})

app.get('/charge', async (req, res) => {
const token = req.query.token
const message = await faucet.charge(token)
console.log("all Tokens: ", getEncodedProofs(faucet.balance ,[{url:process.env.MINT_URL, keysets: [...new Set(faucet.currentToken.map(t=>t.id))]}]))
res.send({message})
})

app.listen(port, async () => {
const cashuMint = new CashuMint(process.env.MINT_URL)
const keys = await cashuMint.getKeys()
const cashuWallet = new CashuWallet(keys, cashuMint)
faucet = new Faucet(cashuWallet, process.env.FAUCET_INTERVAL, process.env.SATS_PER_INTERVAL)
faucet = new AnarchoFaucet(process.env.FAUCET_INTERVAL, process.env.SATS_PER_INTERVAL)
await faucet.start()
console.log(`Example app listening on port ${port}`)
})
Expand Down

0 comments on commit 4f60d4c

Please sign in to comment.