lib/nanook/wallet.rb in nanook-2.4.0 vs lib/nanook/wallet.rb in nanook-2.5.0

- old
+ new

@@ -31,11 +31,11 @@ # The RPC and therefore Nanook cannot tell you what a wallet's seed is, # only its id. Knowing a wallet's seed is very useful for if you ever # want to restore the wallet anywhere else on the nano network besides # the node you originally created it on. The nano command line interface # (CLI) is the only method for discovering a wallet's seed. See the - # {https://github.com/nanocurrency/raiblocks/wiki/Command-line-interface + # {https://developers.nano.org/docs/command-line-interface/#wallet_decrypt_unsafe # --wallet_decrypt_unsafe CLI command}. # # === Initializing # # Initialize this class through the convenient {Nanook#wallet} method: @@ -65,11 +65,11 @@ # See {Nanook::WalletAccount} for all the methods you can call on the # account object returned. # # ==== Examples: # - # wallet.account("xrb_...") # => Nanook::WalletAccount + # wallet.account("nano_...") # => Nanook::WalletAccount # wallet.account.create # => Nanook::WalletAccount # # @param [String] account optional String of an account (starting with # <tt>"xrb..."</tt>) to start working with. Must be an account within # the wallet. When no account is given, the instance returned only @@ -126,15 +126,15 @@ # wallet.balance(account_break_down: true) # # Example response: # # { - # "xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpi00000000"=>{ + # "nano_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpi00000000"=>{ # "balance"=>2.5, # "pending"=>1 # }, - # "xrb_1e5aqegc1jb7qe964u4adzmcezyo6o146zb8hm6dft8tkp79za3sxwjym5rx"=>{ + # "nano_1e5aqegc1jb7qe964u4adzmcezyo6o146zb8hm6dft8tkp79za3sxwjym5rx"=>{ # "balance"=>51.4, # "pending"=>0 # }, # } # @@ -169,10 +169,13 @@ end end # Changes a wallet's seed. # + # It's recommended to only change the seed of a wallet that contains + # no accounts. + # # ==== Example: # # wallet.change_seed("000D1BA...") # => true # # @param seed [String] the seed to change to. @@ -225,13 +228,13 @@ end # Will return +true+ if the account exists in the wallet. # # ==== Example: - # wallet.contains?("xrb_...") # => true + # wallet.contains?("nano_...") # => true # - # @param account [String] id (will start with <tt>"xrb_..."</tt>) + # @param account [String] id (will start with <tt>"nano_..."</tt>) # @return [Boolean] indicating if the wallet contains the given account def contains?(account) wallet_required! response = rpc(:wallet_contains, account: account) !response.empty? && response[:exists] == 1 @@ -249,21 +252,21 @@ # Makes a payment from an account in your wallet to another account # on the nano network. # # Note, there may be a delay in receiving a response due to Proof of - # Work being done. From the {Nano RPC}[https://github.com/nanocurrency/raiblocks/wiki/RPC-protocol#account-create]: + # Work being done. From the {Nano RPC}[https://developers.nano.org/docs/rpc#send]: # # <i>Proof of Work is precomputed for one transaction in the # background. If it has been a while since your last transaction it # will send instantly, the next one will need to wait for Proof of # Work to be generated.</i> # # ==== Examples: # - # wallet.pay(from: "xrb_...", to: "xrb_...", amount: 1.1, id: "myUniqueId123") # => "9AE2311..." - # wallet.pay(from: "xrb_...", to: "xrb_...", amount: 54000000000000, unit: :raw, id: "myUniqueId123") # => "9AE2311..." + # wallet.pay(from: "nano_...", to: "nano_...", amount: 1.1, id: "myUniqueId123") # => "9AE2311..." + # wallet.pay(from: "nano_...", to: "nano_...", amount: 54000000000000, unit: :raw, id: "myUniqueId123") # => "9AE2311..." # # @param from [String] account id of an account in your wallet # @param to (see Nanook::WalletAccount#pay) # @param amount (see Nanook::WalletAccount#pay) # @param unit (see Nanook::Account#balance) @@ -290,15 +293,15 @@ # wallet.pending # # Example response: # # { - # :xrb_1111111111111111111111111111111111111111111111111117353trpda=>[ + # :nano_1111111111111111111111111111111111111111111111111117353trpda=>[ # "142A538F36833D1CC78B94E11C766F75818F8B940771335C6C1B8AB880C5BB1D", # "718CC2121C3E641059BC1C2CFC45666C99E8AE922F7A807B7D07B62C995D79E2" # ], - # :xrb_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3=>[ + # :nano_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3=>[ # "4C1FEEF0BEA7F50BE35489A1233FE002B212DEA554B55B1B470D78BD8F210C74" # ] # } # # Asking for more information: @@ -306,26 +309,26 @@ # wallet.pending(detailed: true) # # Example response: # # { - # :xrb_1111111111111111111111111111111111111111111111111117353trpda=>[ + # :nano_1111111111111111111111111111111111111111111111111117353trpda=>[ # { # :amount=>6.0, - # :source=>"xrb_3dcfozsmekr1tr9skf1oa5wbgmxt81qepfdnt7zicq5x3hk65fg4fqj58mbr", + # :source=>"nano_3dcfozsmekr1tr9skf1oa5wbgmxt81qepfdnt7zicq5x3hk65fg4fqj58mbr", # :block=>:"142A538F36833D1CC78B94E11C766F75818F8B940771335C6C1B8AB880C5BB1D" # }, # { # :amount=>12.0, - # :source=>"xrb_3dcfozsmekr1tr9skf1oa5wbgmxt81qepfdnt7zicq5x3hk65fg4fqj58mbr", + # :source=>"nano_3dcfozsmekr1tr9skf1oa5wbgmxt81qepfdnt7zicq5x3hk65fg4fqj58mbr", # :block=>:"242A538F36833D1CC78B94E11C766F75818F8B940771335C6C1B8AB880C5BB1D" # } # ], - # :xrb_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3=>[ + # :nano_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3=>[ # { # :amount=>106.370018, - # :source=>"xrb_13ezf4od79h1tgj9aiu4djzcmmguendtjfuhwfukhuucboua8cpoihmh8byo", + # :source=>"nano_13ezf4od79h1tgj9aiu4djzcmmguendtjfuhwfukhuucboua8cpoihmh8byo", # :block=>:"4C1FEEF0BEA7F50BE35489A1233FE002B212DEA554B55B1B470D78BD8F210C74" # } # ] # } def pending(limit:1000, detailed:false, unit:Nanook.default_unit) @@ -393,11 +396,11 @@ # Changing the default representative for a wallet does not change # the representatives for any accounts that have been created. # # ==== Example: # - # wallet.default_representative # => "xrb_3pc..." + # wallet.default_representative # => "nano_3pc..." # # @return [String] Representative account of the account def default_representative rpc(:wallet_representative)[:representative] end @@ -409,11 +412,11 @@ # wallet does not change the representatives for existing accounts # in the wallet. # # ==== Example: # - # wallet.change_default_representative("xrb_...") # => "xrb_..." + # wallet.change_default_representative("nano_...") # => "nano_..." # # @param [String] representative the id of the representative account # to set as this account's representative # @return [String] the representative account id # @raise [ArgumentError] if the representative account does not exist @@ -468,11 +471,11 @@ # # { # id: "2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570", # accounts: [ # { - # id: "xrb_11119gbh8hb4hj1duf7fdtfyf5s75okzxdgupgpgm1bj78ex3kgy7frt3s9n" + # id: "nano_11119gbh8hb4hj1duf7fdtfyf5s75okzxdgupgpgm1bj78ex3kgy7frt3s9n" # frontier: "E71AF3E9DD86BBD8B4620EFA63E065B34D358CFC091ACB4E103B965F95783321", # open_block: "643B77F1ECEFBDBE1CC909872964C1DBBE23A6149BD3CEF2B50B76044659B60F", # representative_block: "643B77F1ECEFBDBE1CC909872964C1DBBE23A6149BD3CEF2B50B76044659B60F", # balance: 1.45, # modified_timestamp: 1511476234, @@ -501,9 +504,22 @@ { id: @wallet, accounts: accounts }.to_symbolized_hash + end + + # Locks the wallet. A locked wallet cannot pocket pending transactions or make payments. See {#unlock}. + # + # ==== Example: + # + # wallet.lock #=> true + # + # @return [Boolean] indicates if the wallet was successfully locked + def lock + wallet_required! + response = rpc(:wallet_lock) + !response.empty? && response[:locked] == 1 end # Returns +true+ if the wallet is locked. # # ==== Example: