Method: Hive::Broadcast.escrow_transfer

Defined in:
lib/hive/broadcast.rb

.escrow_transfer(options, &block) ⇒ Object

The purpose of this operation is to enable someone to send money contingently to another individual.

Parameters:

  • options (Hash)

    options

Options Hash (options):

  • :wif (String)

    Active wif

  • :params (Hash)
    • :from (String)

    • :to (String)

    • :agent (String)

    • :escrow_id (String)

    • :hbd_amount (String)

    • :hive_amount (String)

    • :fee (String)

    • :ratification_deadline (String)

    • :escrow_expiration (String)

    • :meta (Hash) Meta of the escrow transfer, becomes ‘json_meta`.

    • :json_meta (String) String version of ‘metadata` (use one or the other).

  • :pretend (Boolean)

    Just validate, do not broadcast.

See Also:



969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
# File 'lib/hive/broadcast.rb', line 969

def self.escrow_transfer(options, &block)
  required_fields = %i(from to agent escrow_id fee ratification_deadline)
  params = options[:params]
  
  if !!params[:meta] && !!params[:json_meta]
    raise Hive::ArgumentError, 'Assign either meta or json_meta, not both.'
  end
  
  meta = params.delete(:meta) || {}
  meta ||= (JSON[params[:json_meta]] || nil) || {}
  params[:json_meta] = meta.to_json
  
  check_required_fields(params, *required_fields)
  
  params[:hbd_amount] = normalize_amount(options.merge amount: params[:hbd_amount])
  params[:hive_amount] = normalize_amount(options.merge amount: params[:hive_amount])
  params[:fee] = normalize_amount(options.merge amount: params[:fee])
  
  params[:ratification_deadline] = Time.parse(params[:ratification_deadline].to_s)
  params[:ratification_deadline] = params[:ratification_deadline].strftime('%Y-%m-%dT%H:%M:%S')
  
  if !!params[:escrow_expiration]
    params[:escrow_expiration] = Time.parse(params[:escrow_expiration].to_s)
    params[:escrow_expiration] = params[:escrow_expiration].strftime('%Y-%m-%dT%H:%M:%S')
  end

  ops = [[:escrow_transfer, params]]
  
  process(options.merge(ops: ops), &block)
end