Initial novacoin support
[electrum-nvc.git] / lib / commands.py
index 5cb030e..30a38b3 100644 (file)
@@ -53,8 +53,8 @@ payto_options = ' --fee, -f: set transaction fee\n --fromaddr, -F: send from add
 listaddr_options = " -a: show all addresses, including change addresses\n -l: include labels in results"
 restore_options = " accepts a seed or master public key."
 mksendmany_syntax = 'mksendmanytx <recipient> <amount> [<recipient> <amount> ...]'
-payto_syntax = "payto <recipient> <amount> [label]\n<recipient> can be a bitcoin address or a label"
-paytomany_syntax = "paytomany <recipient> <amount> [<recipient> <amount> ...]\n<recipient> can be a bitcoin address or a label"
+payto_syntax = "payto <recipient> <amount> [label]\n<recipient> can be a novacoin address or a label"
+paytomany_syntax = "paytomany <recipient> <amount> [<recipient> <amount> ...]\n<recipient> can be a novacoin address or a label"
 signmessage_syntax = 'signmessage <address> <message>\nIf you want to lead or end a message with spaces, or want double spaces inside the message make sure you quote the string. I.e. " Hello  This is a weird String "'
 verifymessage_syntax = 'verifymessage <address> <signature> <message>\nIf you want to lead or end a message with spaces, or want double spaces inside the message make sure you quote the string. I.e. " Hello  This is a weird String "'
 
@@ -65,11 +65,11 @@ verifymessage_syntax = 'verifymessage <address> <signature> <message>\nIf you wa
 #                                                            requires_password
 register_command('contacts',             0, 0, False, True,  False, 'Show your list of contacts')
 register_command('create',               0, 0, False, True,  False, 'Create a new wallet')
-register_command('createmultisig',       2, 2, False, True,  False, 'similar to bitcoind\'s command')
-register_command('createrawtransaction', 2, 2, False, True,  False, 'similar to bitcoind\'s command')
+register_command('createmultisig',       2, 2, False, True,  False, 'similar to novacoind\'s command')
+register_command('createrawtransaction', 2, 2, False, True,  False, 'similar to novacoind\'s command')
 register_command('deseed',               0, 0, False, True,  False, 'Remove seed from wallet, creating a seedless, watching-only wallet.')
-register_command('decoderawtransaction', 1, 1, False, False, False, 'similar to bitcoind\'s command')
-register_command('getprivatekeys',       1, 1, False, True,  True,  'Get the private keys of a given address', 'getprivatekeys <bitcoin address>')
+register_command('decoderawtransaction', 1, 1, False, False, False, 'similar to novacoind\'s command')
+register_command('getprivatekeys',       1, 1, False, True,  True,  'Get the private keys of a given address', 'getprivatekeys <novacoin address>')
 register_command('dumpprivkeys',         0, 0, False, True,  True,  'Dump all private keys in your wallet')
 register_command('freeze',               1, 1, False, True,  True,  'Freeze the funds at one of your wallet\'s addresses', 'freeze <address>')
 register_command('getbalance',           0, 1, True,  True,  False, 'Return the balance of your wallet, or of one account in your wallet', 'getbalance [<account>]')
@@ -78,7 +78,7 @@ register_command('getversion',           0, 0, False, False, False, 'Return the
 register_command('getaddressbalance',    1, 1, True,  False, False, 'Return the balance of an address', 'getaddressbalance <address>')
 register_command('getaddresshistory',    1, 1, True,  False, False, 'Return the transaction history of a wallet address', 'getaddresshistory <address>')
 register_command('getconfig',            1, 1, False, False, False, 'Return a configuration variable', 'getconfig <name>')
-register_command('getpubkeys',           1, 1, False, True,  False, 'Return the public keys for a wallet address', 'getpubkeys <bitcoin address>')
+register_command('getpubkeys',           1, 1, False, True,  False, 'Return the public keys for a wallet address', 'getpubkeys <novacoin address>')
 register_command('getrawtransaction',    1, 1, True,  False, False, 'Retrieve a transaction', 'getrawtransaction <txhash>')
 register_command('getseed',              0, 0, False, True,  True,  'Print the generation seed of your wallet.')
 register_command('getmpk',               0, 0, False, True,  False, 'Return your wallet\'s master public key', 'getmpk')
@@ -146,7 +146,7 @@ class Commands:
 
     def listunspent(self):
         l = copy.deepcopy(self.wallet.get_unspent_coins())
-        for i in l: i["value"] = str(Decimal(i["value"])/100000000)
+        for i in l: i["value"] = str(Decimal(i["value"])/1000000)
         return l
 
     def getaddressunspent(self, addr):
@@ -162,7 +162,7 @@ class Commands:
             i['prevout_hash'] = i['txid']
             i['prevout_n'] = i['vout']
         outputs = map(lambda x: (x[0],int(1e8*x[1])), outputs.items())
-        tx = Transaction(inputs, outputs)
+        tx = Transaction(int(time.time()), inputs, outputs)
         return tx
 
     def signrawtransaction(self, raw_tx, private_keys):
@@ -181,7 +181,7 @@ class Commands:
     def createmultisig(self, num, pubkeys):
         assert isinstance(pubkeys, list)
         redeem_script = Transaction.multisig_script(pubkeys, num)
-        address = hash_160_to_bc_address(hash_160(redeem_script.decode('hex')), 5)
+        address = hash_160_to_bc_address(hash_160(redeem_script.decode('hex')), 20)
         return {'address':address, 'redeemScript':redeem_script}
 
     def freeze(self,addr):
@@ -216,14 +216,14 @@ class Commands:
         else:
             c, u = self.wallet.get_account_balance(account)
 
-        out = { "confirmed": str(Decimal(c)/100000000) }
-        if u: out["unconfirmed"] = str(Decimal(u)/100000000)
+        out = { "confirmed": str(Decimal(c)/1000000) }
+        if u: out["unconfirmed"] = str(Decimal(u)/1000000)
         return out
 
     def getaddressbalance(self, addr):
         out = self.network.synchronous_get([ ('blockchain.address.get_balance',[addr]) ])[0]
-        out["confirmed"] =  str(Decimal(out["confirmed"])/100000000)
-        out["unconfirmed"] =  str(Decimal(out["unconfirmed"])/100000000)
+        out["confirmed"] =  str(Decimal(out["confirmed"])/1000000)
+        out["unconfirmed"] =  str(Decimal(out["unconfirmed"])/1000000)
         return out
 
     def getproof(self, addr):
@@ -239,7 +239,7 @@ class Commands:
         return self.network.get_servers()
 
     def getversion(self):
-        import electrum  # Needs to stay here to prevent ciruclar imports
+        import electrum_nvc  # Needs to stay here to prevent ciruclar imports
         return electrum.ELECTRUM_VERSION
 
     def getmpk(self):
@@ -258,7 +258,7 @@ class Commands:
         return out
 
     def sweep(self, privkey, to_address, fee = 0.0001):
-        fee = int(Decimal(fee)*100000000)
+        fee = int(Decimal(fee)*1000000)
         return Transaction.sweep([privkey], self.network, to_address, fee)
 
     def signmessage(self, address, message):
@@ -270,16 +270,16 @@ class Commands:
     def _mktx(self, outputs, fee = None, change_addr = None, domain = None):
         for to_address, amount in outputs:
             if not is_valid(to_address):
-                raise Exception("Invalid Bitcoin address", to_address)
+                raise Exception("Invalid Novacoin address", to_address)
 
         if change_addr:
             if not is_valid(change_addr):
-                raise Exception("Invalid Bitcoin address", change_addr)
+                raise Exception("Invalid Novacoin address", change_addr)
 
         if domain is not None:
             for addr in domain:
                 if not is_valid(addr):
-                    raise Exception("invalid Bitcoin address", addr)
+                    raise Exception("invalid Novacoin address", addr)
 
                 if not self.wallet.is_mine(addr):
                     raise Exception("address not in wallet", addr)
@@ -296,10 +296,10 @@ class Commands:
                     print_msg("alias", to_address)
                     break
 
-            amount = int(100000000*amount)
+            amount = int(1000000*amount)
             final_outputs.append(('address', to_address, amount))
 
-        if fee: fee = int(100000000*fee)
+        if fee: fee = int(1000000*fee)
         return self.wallet.mktx(final_outputs, self.password, fee , change_addr, domain)
 
     def mktx(self, to_address, amount, fee = None, change_addr = None, domain = None):