Use msat as price unit (#427)

* Use price_msat for config and internally

* Use price_msat in admin protocol for offer message

* Use price_msat in sent payments table and protocol

* Update frontend to use new protocol with price_msat for offer

* Update static build
This commit is contained in:
Jonathan Zernik 2020-11-10 02:35:24 -05:00 committed by GitHub
parent 53fa118f20
commit 6641e64995
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 131 additions and 40 deletions

View file

@ -74,7 +74,8 @@ def run_migrations_online():
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata
target_metadata=target_metadata,
render_as_batch=True,
)
with context.begin_transaction():

View file

@ -0,0 +1,34 @@
"""Use price_msat in sent_payment table
Revision ID: 434b1c53bc45
Revises: e771283d1959
Create Date: 2020-11-10 02:14:57.999127
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '434b1c53bc45'
down_revision = 'e771283d1959'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('sent_payment', schema=None) as batch_op:
batch_op.add_column(sa.Column('price_msat', sa.Integer(), nullable=False, server_default=sa.text("0")))
batch_op.drop_column('amount')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('sent_payment', schema=None) as batch_op:
batch_op.add_column(sa.Column('amount', sa.INTEGER(), nullable=False, server_default=sa.text("0")))
batch_op.drop_column('price_msat')
# ### end Alembic commands ###

View file

@ -1,5 +1,5 @@
[squeaknode]
price=1000
price_msat=1000000
sync_interval_s=10
[lnd]

View file

@ -70,7 +70,7 @@ export default function BuyOfferDetailItem({
return (
<Typography
size="md"
>{offer.getAmount()} msats ({offer.getAmount() / 1000} sats)
>{offer.getPriceMsat()} msats ({offer.getPriceMsat() / 1000} sats)
</Typography>
)
}

View file

@ -97,7 +97,7 @@ export default function BuyOfferDialog({
<DialogTitle id="form-dialog-title">Buy Offer</DialogTitle>
<form className={classes.root} onSubmit={handleSubmit} noValidate autoComplete="off">
<DialogContent>
Are you sure you want to pay {offer.getAmount() / 1000} satoshis for this offer?
Are you sure you want to pay {offer.getPriceMsat() / 1000} satoshis for this offer?
</DialogContent>
<DialogActions>
{CancelButton()}

View file

@ -43,7 +43,7 @@ export default function BuyOfferItem({
return (
<Typography
size="md"
>{offer.getAmount()} msats ({offer.getAmount() / 1000} sats)
>{offer.getPriceMsat()} msats ({offer.getPriceMsat() / 1000} sats)
</Typography>
)
}

View file

@ -1,6 +1,6 @@
[squeaknode]
network=simnet
price=1000
price_msat=1000000
max_squeaks_per_address_per_hour=5
[lnd]

View file

@ -905,6 +905,7 @@ def test_connect_other_node(server_stub, admin_stub, other_server_stub, other_ad
),
)
assert saved_squeak_hash == get_sent_payment_response.sent_payment.squeak_hash
assert 1000000 == get_sent_payment_response.sent_payment.price_msat
def test_download_single_squeak(server_stub, admin_stub, other_server_stub, other_admin_stub, lightning_client, signing_profile_id, saved_squeak_hash):

View file

@ -517,8 +517,8 @@ message OfferDisplayEntry {
/// The squeak hash.
string squeak_hash = 2;
/// The amount
int64 amount = 3;
/// The price in msats
int64 price_msat = 3;
/// The seller node pubkey
string node_pubkey = 4;
@ -594,8 +594,8 @@ message SentPayment {
/// The preimage
string preimage = 6;
/// The amount
int64 amount = 7;
/// The price_msat
int64 price_msat = 7;
/// The seller node pubkey
string node_pubkey = 8;

View file

@ -64,7 +64,7 @@ def offer_entry_to_message(offer_entry):
return squeak_admin_pb2.OfferDisplayEntry(
offer_id=offer.offer_id,
squeak_hash=offer.squeak_hash,
amount=offer.price_msat,
price_msat=offer.price_msat,
node_pubkey=offer.destination,
node_host=offer.node_host,
node_port=offer.node_port,
@ -83,7 +83,7 @@ def sent_payment_to_message(sent_payment):
squeak_hash=sent_payment.squeak_hash,
preimage_hash=sent_payment.preimage_hash,
preimage=sent_payment.preimage,
amount=sent_payment.amount,
price_msat=sent_payment.price_msat,
node_pubkey=sent_payment.node_pubkey,
preimage_is_valid=sent_payment.preimage_is_valid,
)

View file

@ -1,14 +1,14 @@
{
"files": {
"main.js": "/static/js/main.3bc05199.chunk.js",
"main.js.map": "/static/js/main.3bc05199.chunk.js.map",
"main.js": "/static/js/main.43e96e28.chunk.js",
"main.js.map": "/static/js/main.43e96e28.chunk.js.map",
"runtime-main.js": "/static/js/runtime-main.9f0ba400.js",
"runtime-main.js.map": "/static/js/runtime-main.9f0ba400.js.map",
"static/css/2.68adb498.chunk.css": "/static/css/2.68adb498.chunk.css",
"static/js/2.de6713bf.chunk.js": "/static/js/2.de6713bf.chunk.js",
"static/js/2.de6713bf.chunk.js.map": "/static/js/2.de6713bf.chunk.js.map",
"index.html": "/index.html",
"precache-manifest.d9ce98106bc4174c967831fdcc904484.js": "/precache-manifest.d9ce98106bc4174c967831fdcc904484.js",
"precache-manifest.c042e5b9406826bd6f503535e9c04356.js": "/precache-manifest.c042e5b9406826bd6f503535e9c04356.js",
"service-worker.js": "/service-worker.js",
"static/css/2.68adb498.chunk.css.map": "/static/css/2.68adb498.chunk.css.map",
"static/js/2.de6713bf.chunk.js.LICENSE.txt": "/static/js/2.de6713bf.chunk.js.LICENSE.txt",
@ -20,6 +20,6 @@
"static/js/runtime-main.9f0ba400.js",
"static/css/2.68adb498.chunk.css",
"static/js/2.de6713bf.chunk.js",
"static/js/main.3bc05199.chunk.js"
"static/js/main.43e96e28.chunk.js"
]
}

View file

@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><title>Squeak Node</title><meta name="description" content="Squeak Node is a frontend for accessing a squeak node"><meta name="keywords" content="squeak, bitcoin, lightning"><meta name="author" content="Flatlogic LLC."><link href="/static/css/2.68adb498.chunk.css" rel="stylesheet"></head><body style="font-family:Roboto,sans-serif"><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,f,l=r[0],a=r[1],i=r[2],c=0,s=[];c<l.length;c++)f=l[c],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,i||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,l=1;l<t.length;l++){var a=t[l];0!==o[a]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var l=this["webpackJsonpsqueak-node-frontend"]=this["webpackJsonpsqueak-node-frontend"]||[],a=l.push.bind(l);l.push=r,l=l.slice();for(var i=0;i<l.length;i++)r(l[i]);var p=a;t()}([])</script><script src="/static/js/2.de6713bf.chunk.js"></script><script src="/static/js/main.3bc05199.chunk.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><title>Squeak Node</title><meta name="description" content="Squeak Node is a frontend for accessing a squeak node"><meta name="keywords" content="squeak, bitcoin, lightning"><meta name="author" content="Flatlogic LLC."><link href="/static/css/2.68adb498.chunk.css" rel="stylesheet"></head><body style="font-family:Roboto,sans-serif"><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,f,l=r[0],a=r[1],i=r[2],c=0,s=[];c<l.length;c++)f=l[c],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,i||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,l=1;l<t.length;l++){var a=t[l];0!==o[a]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var l=this["webpackJsonpsqueak-node-frontend"]=this["webpackJsonpsqueak-node-frontend"]||[],a=l.push.bind(l);l.push=r,l=l.slice();for(var i=0;i<l.length;i++)r(l[i]);var p=a;t()}([])</script><script src="/static/js/2.de6713bf.chunk.js"></script><script src="/static/js/main.43e96e28.chunk.js"></script></body></html>

View file

@ -0,0 +1,54 @@
self.__precacheManifest = (self.__precacheManifest || []).concat([
{
"revision": "0d942b085cb2e9631daa0231912ce3a6",
"url": "/index.html"
},
{
"revision": "d239eb147962b2534de9",
"url": "/static/css/2.68adb498.chunk.css"
},
{
"revision": "d239eb147962b2534de9",
"url": "/static/js/2.de6713bf.chunk.js"
},
{
"revision": "d92829c3e9f72dcd719b3bd85bf36851",
"url": "/static/js/2.de6713bf.chunk.js.LICENSE.txt"
},
{
"revision": "3023b822a33f688f26a3",
"url": "/static/js/main.43e96e28.chunk.js"
},
{
"revision": "cc9816de5a8639d377ea",
"url": "/static/js/runtime-main.9f0ba400.js"
},
{
"revision": "674f50d287a8c48dc19ba404d20fe713",
"url": "/static/media/fontawesome-webfont.674f50d2.eot"
},
{
"revision": "912ec66d7572ff821749319396470bde",
"url": "/static/media/fontawesome-webfont.912ec66d.svg"
},
{
"revision": "af7ae505a9eed503f8b8e6982036873e",
"url": "/static/media/fontawesome-webfont.af7ae505.woff2"
},
{
"revision": "b06871f281fee6b241d60582ae9369b9",
"url": "/static/media/fontawesome-webfont.b06871f2.ttf"
},
{
"revision": "fee66e712a8a08eef5805a46892932ad",
"url": "/static/media/fontawesome-webfont.fee66e71.woff"
},
{
"revision": "695a31606b1abb167b03fb1f6375831d",
"url": "/static/media/google.695a3160.svg"
},
{
"revision": "a0185b043dee68a72aebffdcc939e21e",
"url": "/static/media/logo.a0185b04.svg"
}
]);

View file

@ -14,7 +14,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
importScripts(
"/precache-manifest.d9ce98106bc4174c967831fdcc904484.js"
"/precache-manifest.c042e5b9406826bd6f503535e9c04356.js"
);
self.addEventListener('message', (event) => {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -60,7 +60,7 @@ class LNDLightningClient:
request = lnd_pb2.WalletBalanceRequest()
return self.stub.WalletBalance(request)
def add_invoice(self, preimage, amount):
def add_invoice(self, preimage, amount_msat):
"""Create a new invoice with the given hash pre-image.
args:
@ -69,7 +69,7 @@ class LNDLightningClient:
"""
invoice = lnd_pb2.Invoice(
r_preimage=preimage,
value=amount,
value_msat=amount_msat,
)
return self.stub.AddInvoice(invoice)

View file

@ -74,7 +74,7 @@ class Config:
# squeaknode
self._configs['squeaknode_network'] = self._get_squeaknode_network()
self._configs['squeaknode_price'] = self._get_squeaknode_price()
self._configs['squeaknode_price_msat'] = self._get_squeaknode_price_msat()
self._configs['squeaknode_max_squeaks_per_address_per_hour'] = self._get_squeaknode_max_squeaks_per_address_per_hour()
self._configs['squeaknode_database'] = self._get_squeaknode_database()
self._configs['squeaknode_sqk_dir'] = self._get_squeaknode_sqk_dir()
@ -179,8 +179,8 @@ class Config:
return environ.get('NETWORK') \
or self.parser.get("squeaknode", "network", fallback="testnet")
def _get_squeaknode_price(self):
return int(self.parser.get("squeaknode", "price", fallback="10"))
def _get_squeaknode_price_msat(self):
return int(self.parser.get("squeaknode", "price_msat", fallback="10000"))
def _get_squeaknode_max_squeaks_per_address_per_hour(self):
return int(self.parser.get("squeaknode", "max_squeaks_per_address_per_hour", fallback="100"))

View file

@ -113,7 +113,7 @@ class Models:
Column("squeak_hash", String(64), nullable=False),
Column("preimage_hash", String(64), nullable=False),
Column("preimage", String(64), nullable=False),
Column("amount", Integer, nullable=False),
Column("price_msat", Integer, nullable=False, default=0),
Column("node_pubkey", String(66), nullable=False),
Column("preimage_is_valid", Boolean, nullable=False),
)

View file

@ -888,7 +888,7 @@ class SqueakDb:
squeak_hash=sent_payment.squeak_hash,
preimage_hash=sent_payment.preimage_hash,
preimage=sent_payment.preimage,
amount=sent_payment.amount,
price_msat=sent_payment.price_msat,
node_pubkey=sent_payment.node_pubkey,
preimage_is_valid=sent_payment.preimage_is_valid,
)
@ -1022,7 +1022,7 @@ class SqueakDb:
squeak_hash=row["squeak_hash"],
preimage_hash=row["preimage_hash"],
preimage=row["preimage"],
amount=row["amount"],
price_msat=row["price_msat"],
node_pubkey=row["node_pubkey"],
preimage_is_valid=row["preimage_is_valid"],
)

View file

@ -75,8 +75,8 @@ def load_network(config):
return config.squeaknode_network
def load_price(config):
return config.squeaknode_price
def load_price_msat(config):
return config.squeaknode_price_msat
def load_database(config):
@ -209,7 +209,7 @@ def run_server(config):
squeak_db.init()
# load the price
price = load_price(config)
price_msat = load_price_msat(config)
# load the max squeaks per block per address
max_squeaks_per_address_per_hour = load_max_squeaks_per_address_per_hour(config)
@ -230,7 +230,7 @@ def run_server(config):
blockchain_client,
lightning_client,
lightning_host_port,
price,
price_msat,
max_squeaks_per_address_per_hour,
sync_interval_s,
)

View file

@ -37,7 +37,7 @@ class SqueakNode:
blockchain_client,
lightning_client,
lightning_host_port,
price,
price_msat,
max_squeaks_per_address_per_hour,
sync_interval_s,
):
@ -45,7 +45,7 @@ class SqueakNode:
self.blockchain_client = blockchain_client
self.lightning_client = lightning_client
self.lightning_host_port = lightning_host_port
self.price = price
self.price_msat = price_msat
self.sync_interval_s = sync_interval_s
self.squeak_block_verifier = SqueakBlockVerifier(postgres_db, blockchain_client)
self.squeak_block_periodic_worker = SqueakBlockPeriodicWorker(
@ -124,10 +124,8 @@ class SqueakNode:
encrypted_decryption_key = CEncryptedDecryptionKey.from_decryption_key(
decryption_key, preimage, iv
)
# Get the offer price
amount = self.price
# Create the lightning invoice
add_invoice_response = self.lightning_client.add_invoice(preimage, amount)
add_invoice_response = self.lightning_client.add_invoice(preimage, self.price_msat)
preimage_hash = add_invoice_response.r_hash
invoice_payment_request = add_invoice_response.payment_request
# Get the lightning network node pubkey
@ -138,7 +136,7 @@ class SqueakNode:
squeak_hash,
encrypted_decryption_key,
iv,
amount,
self.price_msat,
preimage_hash,
invoice_payment_request,
pubkey,
@ -289,7 +287,7 @@ class SqueakNode:
squeak_hash=offer.squeak_hash,
preimage_hash=offer.payment_hash,
preimage=preimage.hex(),
amount=offer.price_msat,
price_msat=offer.price_msat,
node_pubkey=offer.destination,
preimage_is_valid=is_valid_preimage,
)

View file

@ -4,7 +4,7 @@ class BuyOffer:
squeak_hash,
key_cipher,
iv,
amount,
price_msat,
preimage_hash,
payment_request,
pubkey,
@ -15,7 +15,7 @@ class BuyOffer:
self.squeak_hash = squeak_hash
self.key_cipher = key_cipher
self.iv = iv
self.amount = amount
self.price_msat = price_msat
self.preimage_hash = preimage_hash
self.payment_request = payment_request
self.pubkey = pubkey

View file

@ -2,5 +2,5 @@ from collections import namedtuple
SentPayment = namedtuple(
"SentPayment",
"sent_payment_id, offer_id, peer_id, squeak_hash, preimage_hash, preimage, amount, node_pubkey, preimage_is_valid",
"sent_payment_id, offer_id, peer_id, squeak_hash, preimage_hash, preimage, price_msat, node_pubkey, preimage_is_valid",
)