Sha256: f0f025ccbc8de4458ae3e2fcea65eef60d8a7da9a97a5f0d44bf965d2536befd

Contents?: true

Size: 1.2 KB

Versions: 20

Compression:

Stored size: 1.2 KB

Contents

module Etherlite
  module Account
    class Local < Base
      def unlock(_passphrase)
        @passphrase = _passphrase
      end

      def lock
        @passphrase = nil
      end

      def send_transaction(_options = {})
        params = build_params_from_options _options
        passphrase = _options.fetch(:passphrase, @passphrase)

        Transaction.new @connection, send_transaction_with_passphrase(params, passphrase)
      end

      private

      def build_params_from_options(_opt)
        { from: json_encoded_address }.tap do |pr|
          pr[:to] = Utils.encode_address_param(_opt[:to]) if _opt.key? :to
          pr[:value] = Utils.encode_quantity_param(_opt[:value]) if _opt.key? :value
          pr[:data] = _opt[:data] if _opt.key? :data
          pr[:gas] = Utils.encode_quantity_param(_opt[:gas]) if _opt.key? :gas
          pr[:gasPrice] = Utils.encode_quantity_param(_opt[:gas_price]) if _opt.key? :gas_price
        end
      end

      def send_transaction_with_passphrase(_params, _passphrase)
        if _passphrase.nil?
          @connection.eth_send_transaction _params
        else
          @connection.personal_send_transaction _params, _passphrase
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
etherlite-0.6.0 lib/etherlite/account/local.rb
etherlite-0.5.3 lib/etherlite/account/local.rb
etherlite-0.5.2 lib/etherlite/account/local.rb
etherlite-0.5.1 lib/etherlite/account/local.rb
etherlite-0.5.0 lib/etherlite/account/local.rb
etherlite-0.4.2 lib/etherlite/account/local.rb
etherlite-0.4.1 lib/etherlite/account/local.rb
etherlite-0.4.0 lib/etherlite/account/local.rb
etherlite-0.3.0 lib/etherlite/account/local.rb
etherlite-0.2.6 lib/etherlite/account/local.rb
etherlite-0.2.5 lib/etherlite/account/local.rb
etherlite-0.2.4 lib/etherlite/account/local.rb
etherlite-0.2.3 lib/etherlite/account/local.rb
etherlite-0.2.2 lib/etherlite/account/local.rb
etherlite-0.2.1 lib/etherlite/account/local.rb
etherlite-0.2.0 lib/etherlite/account/local.rb
etherlite-0.1.8 lib/etherlite/account/local.rb
etherlite-0.1.7 lib/etherlite/account/local.rb
etherlite-0.1.6 lib/etherlite/account/local.rb
etherlite-0.1.5 lib/etherlite/account/local.rb