This commit is contained in:
npub1smarczws3grrrm3vgd3t6tx6vw25xn48jdqv7xrujnf5c5ghh7ps5yj78s 2024-05-24 10:52:44 +02:00
commit 9e8b692d0c
No known key found for this signature in database
7 changed files with 248 additions and 0 deletions

1
.txo/txo.txt Normal file
View File

@ -0,0 +1 @@
txo:tbtc4:21ebc6077ae613d266dcd45ec1b90c54e228d02c945a7754cdd4dcf63e563d13:0 10000

3
README.md Normal file
View File

@ -0,0 +1,3 @@
`sethue` allows you to set a value between 0 and 360 that will be used as the "hue" of the background-color of this website in an HSL formula.
Be sure to pay at least 1000 sat as the price for having this amazing color-changing opportunity!

20
contract.lua Normal file
View File

@ -0,0 +1,20 @@
function __init__ ()
return {hue=0}
end
function sethue ()
if call.msatoshi < 1000000 then
error('pay at least 1000 sats!')
end
if type(call.payload.hue) ~= 'number' then
error('hue is not a number!')
end
if call.payload.hue < 0 or call.payload.hue > 360 then
error('hue is out of the 0~360 range!')
end
contract.state.hue = call.payload.hue
contract.send('86fa35962e3c40d400f983422284ce5470fb7c3900deb0606d1e2be8ba0f5d9a', call.msatoshi)
end

219
index.html Normal file
View File

@ -0,0 +1,219 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Refresh every hour (3600 seconds) -->
<meta http-equiv="refresh" content="3600" />
<style>
body {
font-family: Arial, sans-serif;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th,
td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
a {
color: #3498db;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
<title>Ledgr</title>
</head>
<body>
<div id="root"></div>
<script type="module">
import {
html, // Import html from htm instead of h
render,
Component
} from 'https://unpkg.com/htm/preact/standalone.module.js'
import 'https://cdn.skypack.dev/nostrefresh'
class App extends Component {
constructor() {
super()
this.state = { fileContent: '', readmeContent: '' } // Initialize state to store file content
}
async componentDidMount() {
try {
var response = await fetch('./.txo/txo.txt') // Fetch the file
if (!response.ok) {
throw new Error(
`Failed to fetch text file: ${response.statusText}`
)
}
var txt = await response.text()
this.setState({ fileContent: txt }) // Update state with file content
response = await fetch('./ledgr.json') // Fetch the file
if (!response.ok) {
throw new Error(
`Failed to fetch text file: ${response.statusText}`
)
}
txt = await response.text()
this.setState({ ledgrContent: txt }) // Update state with file content
response = await fetch('./state.json') // Fetch the file
if (!response.ok) {
throw new Error(
`Failed to fetch text file: ${response.statusText}`
)
}
txt = await response.text()
this.setState({ stateContent: txt }) // Update state with file content
response = await fetch('./README.md') // Fetch the file
if (!response.ok) {
throw new Error(
`Failed to fetch text file: ${response.statusText}`
)
}
txt = await response.text()
this.setState({ readmeContent: txt }) // Update state with file content
} catch (error) {
console.error('Error fetching file:', error)
}
}
render() {
var lines = this.state.fileContent.split('\n')
// Use the html function for creating elements
var assets = 0
var ledgr
var chain = 'tbtc4'
console.log('ledgr', this.state.ledgrContent)
if (this.state.ledgrContent) {
ledgr = JSON.parse(this.state.ledgrContent)
ledgr = Object.entries(ledgr)
}
if (this?.state?.stateContent) {
var hue = JSON.parse(this.state.stateContent)
console.log('hue', hue.hue)
document.body.style.backgroundColor = `hsl(${hue.hue}, 66%, 89%)`
}
console.log('ledgr', ledgr)
var href
return html`
<div>
<h2>README</h2>
<pre>${this.state.readmeContent}</pre>
<h2>State</h2>
<pre>
${this.state.stateContent}
</pre
>
<h2>Contract</h2>
<a href="./contract.lua">view source</a>
<h2>Proofs</h2>
<table>
<thead>
<tr>
<th>Transaction</th>
<th>Reserves</th>
<th>Proof</th>
<th>Verified</th>
</tr>
</thead>
<tbody>
${lines.map((l, i) => {
var double = l.split(' ')
console.log(double)
if (double.length !== 2) return
chain = double[0].split(':')[1]
assets = double[1]
if (chain === 'tbtc4') {
href =
'https://mempool.space/testnet4/tx/' +
double[0].split(':')[2]
}
if (chain === 'vtc') {
href =
'https://vtc5.trezor.io/tx/' + double[0].split(':')[2]
}
return html`<tr>
<td>
<a target="_blank" href="${href}">${double[0]}</a>
</td>
<td>${assets}</td>
<td><a href="${href}">Proof</a></td>
<td></td>
</tr>`
})}
</tbody>
</table>
</div>
<h2>Reserves</h2>
<table>
<thead>
<tr>
<th>Reserves</th>
<th>Chain</th>
<th>Proof</th>
<th>Verified</th>
</tr>
</thead>
<tbody>
<tr>
<td>${assets}</td>
<td>${chain}</td>
<td><a href="${href}">Proof</a></td>
<td></td>
</tr>
</tbody>
</table>
<h2>Ledgr</h2>
<table>
<thead>
<tr>
<th>User</th>
<th>Amount</th>
<th>Proof</th>
<th>Verified</th>
</tr>
</thead>
<tbody>
${ledgr?.map((i, l) => {
return html`<tr>
<td>${i[0]}</td>
<td>${i[1]}</td>
<td><a href="${href}">Proof</a></td>
<td></td>
</tr>`
})}
</tbody>
</table>
`
}
}
render(html`<${App} />`, document.getElementById('root'))
</script>
</body>
</html>

1
ledgr.json Normal file
View File

@ -0,0 +1 @@
{}

1
nostr.json Normal file
View File

@ -0,0 +1 @@
{"id":"347ec9ff4f185b8945632f50895fd77787854fb852986b4e143575a218be111f","pubkey":"86fa3c09d08a0631ee2c4362bd2cda6395434ea79340cf187c94d34c5117bf83","created_at":1716540649,"kind":617,"tags":[["r","wss://nostr.rocks:4443/"],["r","ws://melvincarvalho.com:4445/"],["r","ws://localhost:4445/"],["c","txo:tbtc4:21ebc6077ae613d266dcd45ec1b90c54e228d02c945a7754cdd4dcf63e563d13:1"],["repo","http://git.melvincarvalho.com/small/20.git"],["repo","http://git.nostr.rocks/small/20.git"],["repo","http://git.localhost/small/20.git"]],"content":"genesis: small 20","sig":"3f6304f5651e896be431dda04b8f2f2c006ec07aa221d88d6077b258f72aba24e008c576734aad7a32fe016bc2979cf5a07746b2efa4e8d4c902322c13b68973"}

3
state.json Normal file
View File

@ -0,0 +1,3 @@
{
"hue": 90
}