<commit_before>#!/usr/bin/env python
# Copyright (C) 2015 <NAME>
# 
# This file is part of the METAMARKET project.
# 
# It is subject to the license terms in the LICENSE file found in the top-level
# directory of this distribution.
# 
# No part of METAMARKET, including this file, may be copied, modified,
# propagated, or distributed except according to the terms contained in the
# LICENSE file.

from MM_util import *
import bitcoin, bitcoin.rpc, bitcoin.core, pycoin.key.Key
import scrypt, simplecrypt
import simplejson as json
import argparse, ConfigParser
import sys, os, hashlib, getpass, time, decimal
import xmlrpclib, base64

def login( wp=None ):
    global username, passphrase, pkstr, wif, btcaddr, bmaddr, myid, mymarket, bannedtags
    
    print "WELCOME TO METAMARKET--"
    print "Please login--"
    username = raw_input("Name: ")
    passphrase = getpass.getpass("Passphrase: ")
    
    hash = hashlib.sha256(passphrase).hexdigest()
    pkbytes = scrypt.hash(hash, username, N=2**18, buflen=32)
    pkstr = bitcoin.core.b2x(pkbytes)
    se = long(pkstr, 16)
    pk = pycoin.key.Key(secret_exponent=se, netcode=netcode)
    
    wif = pk.wif()
    btcaddr = pk.address()
    bmaddr = bm.getDeterministicAddress( base64.b64encode(pkstr), 4, 1 )
    
    print "BTC Address: %s\nBM Address: %s" % ( btcaddr, bmaddr )
    
    unlockwallet(wp)
    if not btcd.validateaddress(btcaddr)['ismine'] or \
        bm.createDeterministicAddresses(base64.b64encode(pkstr)) != []:
        importkeys()
    
    identlist = loadlist('ident')
    
    myidstr = createidentmsgstr(btcaddr, bmaddr, username)
    myid = MM_loads( btcaddr, myidstr )
    print "My ID: %s" % myid.hash
    
    if not searchlistbyhash(identlist, myid.hash):
        register(myidstr)
    
    if entity == 'mod':
        marketlist = loadlist('market')
        for i in marketlist:
            if i.obj['modid'] == myid.hash:
                mymarket = i
                print "My Market ID:", mymarket.hash
        bannedtags = loadindex('bannedtags')
        
def importkeys( ):
    print "Bitcoin private key not found in wallet"
    print "or Bitmessage identity does not exist."
    print "Import your BTC private key and create your BM ID?"
    if yorn():
        pass2 = getpass.getpass("Please re-enter your passphrase: ")
        if pass2 == passphrase:
            btcd.importprivkey(wif, username, False)
            
            print "REMEMBER TO SECURELY BACKUP YOUR"
            print "wallet.dat AND keys.dat files!"
            print "--------------------------------"
        else:
            raise Exception("Passwords did not match.")
    else:
        bm.deleteAddress(bmaddr)
        sys.exit()
    
def register( idstr ):
    print "We were not able to find your ID on file."
    print "Is this a new identity you would like to create?"
    if not yorn():
        login()
    else:
        MM_writefile(idstr)
        appendindex('ident', myid.hash)
        
        
def synccast( ):
    identlist = loadlist('ident')
    burnlist = loadlist('burn')
    taglist = loadlist('tags')
    offerlist = loadlist('offer')
    feedbacklist = loadlist('feedback')
    
    return createcastmsgstr(btcaddr, myid.hash, \
                identlist, burnlist, taglist, offerlist, feedbacklist)
    
# creates a "CAST Msg" from current lists and broadcasts over BM
def modbroadcast( ):
    bm.sendBroadcast(bmaddr, base64.b64encode('Msg'), base64.b64encode(synccast()))

# creates a "CAST Msg" from current lists and sends to new user
def modsync( bm_addr ):
    sendmsgviabm(bm_addr, bmaddr, synccast(), False)

def do_modbanuser( ):
    userid = raw_input("Enter a User ID: ")
    print "Are you sure?:"
    if not yorn():
        return
        
    identlist = loadlist('ident')
    offerlist = loadlist('offer')
    
    modbanuser(userid, identlist, offerlist)
    
def do_modbantag( ):
    taghash = raw_input("Enter a Tag ID: ")
    print "Are you sure?:"
    if not yorn():
        return
        
    offerlist = loadlist('offer')
    bannedtags.append(taghash)
    modbantag(taghash, offerlist, bannedtags)

def do_modremoveoffer( ):
    offerhash = raw_input("Enter an Offer ID: ")
    print "Are you sure?:"
    if not yorn():
        return
    modremoveoffer(offerhash):        
        
    
def do_getrep( identhash, burn_mult ):
    getrep( identhash, burn_mult, loadlist('feedback'), loadlist('burn') )

    
# Takes a list of Verified Msgs and prints info to stdout.
def showanylist( list, mktid=None, marketlist=None ):
    for i in list:
        title = "Name"
        if i.msgname == REG:<commit_msg>Fix typo<commit_after>#!/usr/bin/env python
# Copyright (C) 2015 <NAME>
# 
# This file is part of the METAMARKET project.
# 
# It is subject to the license terms in the LICENSE file found in the top-level
# directory of this distribution.
# 
# No part of METAMARKET, including this file, may be copied, modified,
# propagated, or distributed except according to the terms contained in the
# LICENSE file.

from MM_util import *
import bitcoin, bitcoin.rpc, bitcoin.core, pycoin.key.Key
import scrypt, simplecrypt
import simplejson as json
import argparse, ConfigParser
import sys, os, hashlib, getpass, time, decimal
import xmlrpclib, base64

def login( wp=None ):
    global username, passphrase, pkstr, wif, btcaddr, bmaddr, myid, mymarket, bannedtags
    
    print "WELCOME TO METAMARKET--"
    print "Please login--"
    username = raw_input("Name: ")
    passphrase = getpass.getpass("Passphrase: ")
    
    hash = hashlib.sha256(passphrase).hexdigest()
    pkbytes = scrypt.hash(hash, username, N=2**18, buflen=32)
    pkstr = bitcoin.core.b2x(pkbytes)
    se = long(pkstr, 16)
    pk = pycoin.key.Key(secret_exponent=se, netcode=netcode)
    
    wif = pk.wif()
    btcaddr = pk.address()
    bmaddr = bm.getDeterministicAddress( base64.b64encode(pkstr), 4, 1 )
    
    print "BTC Address: %s\nBM Address: %s" % ( btcaddr, bmaddr )
    
    unlockwallet(wp)
    if not btcd.validateaddress(btcaddr)['ismine'] or \
        bm.createDeterministicAddresses(base64.b64encode(pkstr)) != []:
        importkeys()
    
    identlist = loadlist('ident')
    
    myidstr = createidentmsgstr(btcaddr, bmaddr, username)
    myid = MM_loads( btcaddr, myidstr )
    print "My ID: %s" % myid.hash
    
    if not searchlistbyhash(identlist, myid.hash):
        register(myidstr)
    
    if entity == 'mod':
        marketlist = loadlist('market')
        for i in marketlist:
            if i.obj['modid'] == myid.hash:
                mymarket = i
                print "My Market ID:", mymarket.hash
        bannedtags = loadindex('bannedtags')
        
def importkeys( ):
    print "Bitcoin private key not found in wallet"
    print "or Bitmessage identity does not exist."
    print "Import your BTC private key and create your BM ID?"
    if yorn():
        pass2 = getpass.getpass("Please re-enter your passphrase: ")
        if pass2 == passphrase:
            btcd.importprivkey(wif, username, False)
            
            print "REMEMBER TO SECURELY BACKUP YOUR"
            print "wallet.dat AND keys.dat files!"
            print "--------------------------------"
        else:
            raise Exception("Passwords did not match.")
    else:
        bm.deleteAddress(bmaddr)
        sys.exit()
    
def register( idstr ):
    print "We were not able to find your ID on file."
    print "Is this a new identity you would like to create?"
    if not yorn():
        login()
    else:
        MM_writefile(idstr)
        appendindex('ident', myid.hash)
        
        
def synccast( ):
    identlist = loadlist('ident')
    burnlist = loadlist('burn')
    taglist = loadlist('tags')
    offerlist = loadlist('offer')
    feedbacklist = loadlist('feedback')
    
    return createcastmsgstr(btcaddr, myid.hash, \
                identlist, burnlist, taglist, offerlist, feedbacklist)
    
# creates a "CAST Msg" from current lists and broadcasts over BM
def modbroadcast( ):
    bm.sendBroadcast(bmaddr, base64.b64encode('Msg'), base64.b64encode(synccast()))

# creates a "CAST Msg" from current lists and sends to new user
def modsync( bm_addr ):
    sendmsgviabm(bm_addr, bmaddr, synccast(), False)

def do_modbanuser( ):
    userid = raw_input("Enter a User ID: ")
    print "Are you sure?:"
    if not yorn():
        return
        
    identlist = loadlist('ident')
    offerlist = loadlist('offer')
    
    modbanuser(userid, identlist, offerlist)
    
def do_modbantag( ):
    taghash = raw_input("Enter a Tag ID: ")
    print "Are you sure?:"
    if not yorn():
        return
        
    offerlist = loadlist('offer')
    bannedtags.append(taghash)
    modbantag(taghash, offerlist, bannedtags)

def do_modremoveoffer( ):
    offerhash = raw_input("Enter an Offer ID: ")
    print "Are you sure?:"
    if not yorn():
        return
    modremoveoffer(offerhash)
        
    
def do_getrep( identhash, burn_mult ):
    getrep( identhash, burn_mult, loadlist('feedback'), loadlist('burn') )

    
# Takes a list of Verified Msgs and prints info to stdout.
def showanylist( list, mktid=None, marketlist=None ):
    for i in list:
        title = "Name"
        if i.msgname == REG:
{'fraction_non_alphanumeric': 0.11133998265394622, 'fraction_numerical': 0.008022549869904597, 'mean_word_length': 2.672372611464968, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '429713', 'n_tokens_mistral': 3026, 'n_tokens_neox': 2911, 'n_words': 864}