@@ -500,40 +500,52 @@ UniValue importwallet(const JSONRPCRequest& request)
500
500
if (vstr.size () < 2 )
501
501
continue ;
502
502
CBitcoinSecret vchSecret;
503
- if (!vchSecret.SetString (vstr[0 ]))
504
- continue ;
505
- CKey key = vchSecret.GetKey ();
506
- CPubKey pubkey = key.GetPubKey ();
507
- assert (key.VerifyPubKey (pubkey));
508
- CKeyID keyid = pubkey.GetID ();
509
- if (pwallet->HaveKey (keyid)) {
510
- LogPrintf (" Skipping import of %s (key already present)\n " , EncodeDestination (keyid));
511
- continue ;
512
- }
513
- int64_t nTime = DecodeDumpTime (vstr[1 ]);
514
- std::string strLabel;
515
- bool fLabel = true ;
516
- for (unsigned int nStr = 2 ; nStr < vstr.size (); nStr++) {
517
- if (boost::algorithm::starts_with (vstr[nStr], " #" ))
518
- break ;
519
- if (vstr[nStr] == " change=1" )
520
- fLabel = false ;
521
- if (vstr[nStr] == " reserve=1" )
522
- fLabel = false ;
523
- if (boost::algorithm::starts_with (vstr[nStr], " label=" )) {
524
- strLabel = DecodeDumpString (vstr[nStr].substr (6 ));
525
- fLabel = true ;
503
+ if (vchSecret.SetString (vstr[0 ])) {
504
+ CKey key = vchSecret.GetKey ();
505
+ CPubKey pubkey = key.GetPubKey ();
506
+ assert (key.VerifyPubKey (pubkey));
507
+ CKeyID keyid = pubkey.GetID ();
508
+ if (pwallet->HaveKey (keyid)) {
509
+ LogPrintf (" Skipping import of %s (key already present)\n " , EncodeDestination (keyid));
510
+ continue ;
526
511
}
512
+ int64_t nTime = DecodeDumpTime (vstr[1 ]);
513
+ std::string strLabel;
514
+ bool fLabel = true ;
515
+ for (unsigned int nStr = 2 ; nStr < vstr.size (); nStr++) {
516
+ if (boost::algorithm::starts_with (vstr[nStr], " #" ))
517
+ break ;
518
+ if (vstr[nStr] == " change=1" )
519
+ fLabel = false ;
520
+ if (vstr[nStr] == " reserve=1" )
521
+ fLabel = false ;
522
+ if (boost::algorithm::starts_with (vstr[nStr], " label=" )) {
523
+ strLabel = DecodeDumpString (vstr[nStr].substr (6 ));
524
+ fLabel = true ;
525
+ }
526
+ }
527
+ LogPrintf (" Importing %s...\n " , EncodeDestination (keyid));
528
+ if (!pwallet->AddKeyPubKey (key, pubkey)) {
529
+ fGood = false ;
530
+ continue ;
531
+ }
532
+ pwallet->mapKeyMetadata [keyid].nCreateTime = nTime;
533
+ if (fLabel )
534
+ pwallet->SetAddressBook (keyid, strLabel, " receive" );
535
+ nTimeBegin = std::min (nTimeBegin, nTime);
536
+ } else if (IsHex (vstr[0 ])) {
537
+ std::vector<unsigned char > vData (ParseHex (vstr[0 ]));
538
+ CScript script = CScript (vData.begin (), vData.end ());
539
+ if (pwallet->HaveCScript (script)) {
540
+ LogPrintf (" Skipping import of %s (script already present)\n " , vstr[0 ]);
541
+ continue ;
542
+ }
543
+ if (!pwallet->AddCScript (script)) {
544
+ LogPrintf (" Error importing script %s\n " , vstr[0 ]);
545
+ fGood = false ;
546
+ continue ;
547
+ }
527
548
}
528
- LogPrintf (" Importing %s...\n " , EncodeDestination (keyid));
529
- if (!pwallet->AddKeyPubKey (key, pubkey)) {
530
- fGood = false ;
531
- continue ;
532
- }
533
- pwallet->mapKeyMetadata [keyid].nCreateTime = nTime;
534
- if (fLabel )
535
- pwallet->SetAddressBook (keyid, strLabel, " receive" );
536
- nTimeBegin = std::min (nTimeBegin, nTime);
537
549
}
538
550
file.close ();
539
551
pwallet->ShowProgress (" " , 100 ); // hide progress dialog in GUI
@@ -542,7 +554,7 @@ UniValue importwallet(const JSONRPCRequest& request)
542
554
pwallet->MarkDirty ();
543
555
544
556
if (!fGood )
545
- throw JSONRPCError (RPC_WALLET_ERROR, " Error adding some keys to wallet" );
557
+ throw JSONRPCError (RPC_WALLET_ERROR, " Error adding some keys/scripts to wallet" );
546
558
547
559
return NullUniValue;
548
560
}
0 commit comments