Skip to content

Commit

Permalink
Merge pull request #16 from bismuthfoundation/postfork
Browse files Browse the repository at this point in the history
Merge Postfork Request
  • Loading branch information
EggPool committed Nov 9, 2019
2 parents 51676e5 + ad25d1d commit d1a8f30
Show file tree
Hide file tree
Showing 101 changed files with 2,174 additions and 6,959 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Expand Up @@ -9,15 +9,24 @@ gui.build/
node.build/
workspace/
*.log
*.log.*
node.log.*
wallet.log.*
privkey.der
pubkey.der
wallet.der
address.txt
mempool.db
ledger.db
index.db
static/regmode.
static/regmode.*
static/index_reg.*
heavy3a.bin
/theme
config_custom.txt
sequencing_last
# ignore polysign, so devs can have a symlink or local dev version.
polysign
# ignore ledger queries, for the time being.
ledger_queries.py
55 changes: 26 additions & 29 deletions README.md
Expand Up @@ -2,53 +2,50 @@ Bismuth Readme
=======
##### Warning: For production purposes, please only use code from the "releases" page, which is not in pre-release state.

[![Build Status](https://travis-ci.org/hclivess/Bismuth.svg?branch=master)](https://travis-ci.org/hclivess/Bismuth)

Official website:
### Official website:
* http://bismuth.cz

Hypernodes website:
* https://hypernodes.bismuth.live
### Explorers:
* https://bismuth.online

DApps, miscellaneous:
* https://github.com/hclivess/BismuthProjects
### Wallets:
* [Tornado Wallet](https://github.com/bismuthfoundation/TornadoWallet)
* [tk-wallet](https://github.com/bismuthfoundation/tk-wallet)

API, RPC, Bisafe, HowTo:
* https://github.com/EggPool
### Hypernodes website:
* https://hypernodes.bismuth.live

Explorer, pool, tools:
### Social:
* [Discord](https://discord.gg/dKVZd4z)
* [Blog](https://hypernodes.bismuth.live/?page_id=20)
* [Reddit](https://www.reddit.com/r/cryptobismuth)
* [Facebook](https://web.facebook.com/cryptobismuth)
* [Telegram](https://t.me/cryptobismuth)
* [Egg's Twitter](https://twitter.com/EggPoolNet)
* [Jan's Twitter](https://twitter.com/bismuthdev)
* [Gawlea's Twitter](https://twitter.com/BismuthPlatform)

### Related repositories:
* https://github.com/maccaspacca
* https://github.com/EggPool
* https://github.com/hclivess

### Links:

Bismuth Foundation:
* https://github.com/bismuthfoundation


Twitter:
* https://twitter.com/bismuthplatform
* https://twitter.com/bismuthdev
* https://twitter.com/EggPoolNet

Discord (main support and community place):
* https://discord.gg/dKVZd4z

Facebook:
* https://web.facebook.com/cryptobismuth

Reddit:
* https://www.reddit.com/r/cryptobismuth/

Discord:
* https://discord.gg/dKVZd4z

License:

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
91 changes: 23 additions & 68 deletions aliases.py
@@ -1,81 +1,36 @@
import sqlite3
import re
import log
import functools
import re

def replace_regex(string,replace):
replaced_string = re.sub(r'^{}'.format(replace), "", string)
return replaced_string

def sql_trace_callback(log, id, statement):
line = f"SQL[{id}] {statement}"
log.warning(line)

def aliases_update(f, ledger ,mode, app_log, trace_db_calls=False):
"""Where f is the aliases database file"""
# index aliases
if mode not in ("normal", "reindex"):
raise ValueError ("Wrong value for aliases_update function")

# removed `conn.text_factory = str` because sqlites default `text_factory` is `str`
with sqlite3.connect(ledger) as conn:
if trace_db_calls:
conn.set_trace_callback(functools.partial(sql_trace_callback,app_log,"ALIASES-LEDGER"))
try:
c = conn.cursor()
except:
app_log.error('Failed to create cursor for ledger')
def aliases_update(node, db_handler_instance):
db_handler_instance.index_cursor.execute("SELECT block_height FROM aliases ORDER BY block_height DESC LIMIT 1;")
try:
alias_last_block = int(db_handler_instance.index_cursor.fetchone()[0])
except:
alias_last_block = 0

with sqlite3.connect(f) as ali:
if trace_db_calls:
ali.set_trace_callback(functools.partial(sql_trace_callback,app_log,"ALIASES-F"))
try:
a = ali.cursor()
except:
app_log.error('Failed to create cursor for aliases')
return
node.logger.app_log.warning("Alias anchor block: {}".format(alias_last_block))

try:
a.execute("CREATE TABLE IF NOT EXISTS aliases (block_height INTEGER, address, alias)")
ali.commit()
except:
app_log.error('Failed to create aliases table')
return

if mode == 'reindex':
app_log.warning("Alias database will be reindexed")
try:
a.execute("DELETE FROM aliases")
ali.commit()
except:
app_log.error('Failed to delete content from aliases table')
return

a.execute("SELECT block_height FROM aliases ORDER BY block_height DESC LIMIT 1;")
try:
alias_last_block = int(a.fetchone()[0])
except:
alias_last_block = 0
db_handler_instance.h.execute("SELECT block_height, address, openfield FROM transactions WHERE openfield LIKE ? AND block_height >= ? ORDER BY block_height ASC, timestamp ASC;", ("alias=" + '%',) + (alias_last_block,))
# include the anchor block in case indexation stopped there
result = db_handler_instance.h.fetchall()

app_log.warning("Alias anchor block: {}".format(alias_last_block))

c.execute("SELECT block_height, address, openfield FROM transactions WHERE openfield LIKE ? AND block_height >= ? ORDER BY block_height ASC, timestamp ASC;", ("alias=" + '%',)+(alias_last_block,))
#include the anchor block in case indexation stopped there
result = c.fetchall()

for openfield in result:
alias = (replace_regex(openfield[2], "alias="))
app_log.warning("Processing alias registration: {}".format(alias))
try:
a.execute("SELECT * from aliases WHERE alias = ?", (alias,))
dummy = a.fetchall()[0] #check for uniqueness
app_log.warning("Alias already registered: {}".format(alias))
except:
a.execute("INSERT INTO aliases VALUES (?,?,?)", (openfield[0],openfield[1],alias))
ali.commit()
app_log.warning("Added alias to the database: {} from block {}".format (alias,openfield[0]))
for openfield in result:
alias = (replace_regex(openfield[2], "alias="))
node.logger.app_log.warning(f"Processing alias registration: {alias}")
try:
db_handler_instance.index_cursor.execute("SELECT * from aliases WHERE alias = ?", (alias,))
dummy = db_handler_instance.index_cursor.fetchall()[0] # check for uniqueness
node.logger.app_log.warning(f"Alias already registered: {alias}")
except:
db_handler_instance.index_cursor.execute("INSERT INTO aliases VALUES (?,?,?)", (openfield[0], openfield[1], alias))
db_handler_instance.index.commit()
node.logger.app_log.warning(f"Added alias to the database: {alias} from block {openfield[0]}")


if __name__ == "__main__":
app_log = log.log("aliases.log", "WARNING", True)
aliases_update("static/index.db","static/ledger.db","normal",app_log)

33 changes: 33 additions & 0 deletions aliasesv2.py
@@ -0,0 +1,33 @@
import sqlite3
import re
import log
import functools

def aliases_update(node, db_handler_instance):

db_handler_instance.index_cursor.execute("SELECT block_height FROM aliases ORDER BY block_height DESC LIMIT 1;")
try:
alias_last_block = int(db_handler_instance.index_cursor.fetchone()[0])
except:
alias_last_block = 0

node.logger.app_log.warning("Alias anchor block: {}".format(alias_last_block))

db_handler_instance.h.execute("SELECT block_height, address, openfield FROM transactions WHERE operation = ? AND block_height >= ? AND reward = 0 ORDER BY block_height ASC, timestamp ASC;", ("alias:register", alias_last_block,))
#include the anchor block in case indexation stopped there
result = db_handler_instance.h.fetchall()

for openfield in result:
node.logger.app_log.warning(f"Processing alias registration: {openfield[2]}")
try:
db_handler_instance.index_cursor.execute("SELECT * from aliases WHERE alias = ?", (openfield[2],))
dummy = db_handler_instance.index_cursor.fetchall()[0] #check for uniqueness
node.logger.app_log.warning(f"Alias already registered: {openfield[2]}")
except:
db_handler_instance.index_cursor.execute("INSERT INTO aliases VALUES (?,?,?)", (openfield[0],openfield[1],openfield[2]))
db_handler_instance.index.commit()
node.logger.app_log.warning(f"Added alias to the database: {openfield[2]} from block {openfield[0]}")


if __name__ == "__main__":
app_log = log.log("aliases.log", "WARNING", True)

0 comments on commit d1a8f30

Please sign in to comment.