문제

Trying to work on blockchain-wallet ruby api methods as in doc https://github.com/Tolsi/blockchain-wallet-ruby/blob/master/lib/blockchain/wallet.rb where am stuck with passing Json parameters for payment and sendmany methods.

 recipients = {"1H8fsmAgVhUt567I65hGJPkMbnCCy5": "1000000"}

    wallet = Blockchain::Wallet.new("b14d36af-2fa6-4d76-91b5-ff70b8370ec7", "n$grJ74hAshfggnb6864%j78@#^hChttp://ya.ru@contentpurl", nil)

    wallet.sendmany(recipients, from = nil, shared = nil, fee = nil, note = nil)

Got error despite substituting the required, Invalid Recipients JSON. Please make sure it is url encoded and consult the docs. (WebAPI::WebApiException)

How to solve the problem ?

도움이 되었습니까?

해결책

In the Blockchain::Wallet gem code, I found this:

  def build_url(operation_name, params)
     @url + operation_name + "?" + params.map { |param, value| "#{param}=#{value}" if value }.join("&")
  end 

I believe the way it's being built, you will need to transform in JSON and also encode your recipients string:

  require 'json'
  require 'uri'      

  recipients = {"1H8fsmAgVhUt567I65hGJPkMbnCCy5" => "1000000"}

  wallet = Blockchain::Wallet.new("b14d36af-2fa6-4d76-91b5-ff70b8370ec7", "n$grJ74hAshfggnb6864%j78@#^hChttp://ya.ru@contentpurl", nil)

  wallet.sendmany(URI.encode(JSON.generate(recipients)))

The recipient will be "%7B%221H8fsmAgVhUt567I65hGJPkMbnCCy5%22:%221000000%22%7D".

References:

UPDATE: Try remove the URI.encode if this does not work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top