verify if pr has expired
[electrum-nvc.git] / lib / commands.py
index 4dadf34..5e6d9dc 100644 (file)
@@ -16,6 +16,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
+import time
 from util import *
 from bitcoin import *
 from decimal import Decimal
@@ -62,8 +63,8 @@ register_command('createmultisig',       2, 2, False, True,  False, 'similar to
 register_command('createrawtransaction', 2, 2, False, True,  False, 'similar to bitcoind\'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('dumpprivkey',          1, 1, False, True,  True,  'Dumps a specified private key for a given address', 'dumpprivkey <bitcoin address>')
-register_command('dumpprivkeys',         0, 0, False, True,  True,  'dump all private keys')
+register_command('getprivatekeys',       1, 1, False, True,  True,  'Get the private keys of a given address', 'getprivatekeys <bitcoin 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>]')
 register_command('getservers',           0, 0, True,  False, False, 'Return the list of available servers')
@@ -101,6 +102,7 @@ register_command('decrypt',              2,-1, False, True, True,   'decrypt a m
 register_command('daemon',               1, 1, True, False, False,  '<stop|status>')
 register_command('getproof',             1, 1, True, False, False, 'get merkle proof', 'getproof <address>')
 register_command('getutxoaddress',       2, 2, True, False, False, 'get the address of an unspent transaction output','getutxoaddress <txid> <pos>')
+register_command('sweep',                2, 3, True, False, False, 'Sweep a private key.', 'sweep privkey addr [fee]')
 
 
 
@@ -160,7 +162,9 @@ class Commands:
 
 
     def createrawtransaction(self, inputs, outputs):
-        inputs = map(lambda i: {'prevout_hash': i['txid'], 'prevout_n':i['vout']}, inputs )
+        for i in inputs:
+            i['prevout_hash'] = i['txid']
+            i['prevout_n'] = i['vout']
         outputs = map(lambda x: (x[0],int(1e8*x[1])), outputs.items())
         tx = Transaction.from_io(inputs, outputs)
         return tx
@@ -191,7 +195,7 @@ class Commands:
     def unfreeze(self,addr):
         return self.wallet.unfreeze(addr)
 
-    def dumpprivkey(self, addr):
+    def getprivatekeys(self, addr):
         return self.wallet.get_private_key(addr, self.password)
 
     def dumpprivkeys(self, addresses = None):
@@ -237,6 +241,8 @@ class Commands:
         return out
 
     def getservers(self):
+        while not self.network.is_up_to_date():
+            time.sleep(0.1)
         return self.network.get_servers()
 
     def getversion(self):
@@ -248,8 +254,7 @@ class Commands:
 
     def getseed(self):
         mnemonic = self.wallet.get_mnemonic(self.password)
-        seed = self.wallet.get_seed(self.password)
-        return { 'mnemonic':mnemonic, 'seed':seed, 'version':self.wallet.seed_version }
+        return { 'mnemonic':mnemonic, 'version':self.wallet.seed_version }
 
     def importprivkey(self, sec):
         try:
@@ -260,6 +265,11 @@ class Commands:
         return out
 
 
+    def sweep(self, privkey, to_address, fee = 0.0001):
+        fee = int(Decimal(fee)*100000000)
+        return Transaction.sweep([privkey], self.network, to_address, fee)
+
+
     def signmessage(self, address, message):
         return self.wallet.sign_message(address, message, self.password)