Skip to content
This repository has been archived by the owner on May 20, 2021. It is now read-only.

Commit

Permalink
Enhancement #17 contracts class.
Browse files Browse the repository at this point in the history
  • Loading branch information
krischik committed Jun 13, 2019
1 parent c4205c1 commit ce360e1
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Scripts/SCC/Contract.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/opt/local/bin/ruby
############################################################# {{{1 ##########
# Copyright © 2019 Martin Krischik «krischik@users.sourceforge.net»
#############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see «http://www.gnu.org/licenses/».
############################################################# }}}1 ##########

# use the "steem.rb" file from the radiator gem. This is
# only needed if you have both steem-api and radiator
# installed.

gem "radiator", :require => "steem"

require 'pp'
require 'colorize'
require 'contracts'
require 'radiator'

require_relative 'Steem_Engine'

##
#
module SCC
class Contract < SCC::Steem_Engine
include Contracts::Core
include Contracts::Builtin

attr_reader :name, :owner, :code, :codeHash, :tables

public

Contract String => nil
def initialize(_name)
super(:contract, Steem_Engine.contracts_api.contract(_name))

@name = @value.name
@owner = @value.owner
@code = @value.code
@codeHash = @value.codeHash
@tables = @value.tables

return
end
end # Token
end # SCC

############################################################ {{{1 ###########
# vim: set nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab :
# vim: set textwidth=0 filetype=ruby foldmethod=marker nospell :
# vim: set spell spelllang=en_gb fileencoding=utf-8 :
71 changes: 71 additions & 0 deletions Scripts/SCC/Steem_Engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
############################################################# {{{1 ##########
# Copyright © 2019 Martin Krischik «krischik@users.sourceforge.net»
#############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see «http://www.gnu.org/licenses/».
############################################################# }}}1 ##########

# use the "steem.rb" file from the radiator gem. This is
# only needed if you have both steem-api and radiator
# installed.

gem "radiator", :require => "steem"

require 'pp'
require 'colorize'
require 'contracts'
require 'radiator'

##
#
module SCC
class Steem_Engine < Radiator::Type::Serializer
include Contracts::Core
include Contracts::Builtin

protected

##
# Access to contracts interface
#
# @return ~
#
Contract None => Radiator::SSC::Contracts
def self.contracts_api
# create instance to the steem condenser API which
# will give us access to the median history price

if @@api == nil then
@@api = Radiator::SSC::Contracts.new
end

return @@api
rescue => error
# I am using Kernel::abort so the code snipped
# including error handler can be copy pasted into other
# scripts

Kernel::abort("Error creating contracts API :\n".red + error.to_s)
end #contracts

private

@@api = nil

end # Token
end # SCC

############################################################ {{{1 ###########
# vim: set nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab :
# vim: set textwidth=0 filetype=ruby foldmethod=marker nospell :
# vim: set spell spelllang=en_gb fileencoding=utf-8 :
64 changes: 64 additions & 0 deletions Scripts/SCC/Token.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/opt/local/bin/ruby
############################################################# {{{1 ##########
# Copyright © 2019 Martin Krischik «krischik@users.sourceforge.net»
#############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see «http://www.gnu.org/licenses/».
############################################################# }}}1 ##########

# use the "steem.rb" file from the radiator gem. This is
# only needed if you have both steem-api and radiator
# installed.

gem "radiator", :require => "steem"

require 'pp'
require 'colorize'
require 'contracts'
require 'radiator'

##
#
module SCC
class Token
include Contracts::Core
include Contracts::Builtin

public

def find (String _name)
_contract = Contracts.contract _name
end

private
def self.contracts
# create instance to the steem condenser API which
# will give us access to the median history price

@contracts ||= Radiator::SSC::Contracts.new

return @contracts
rescue => error
# I am using Kernel::abort so the code snipped
# including error handler can be copy pasted into other
# scripts

Kernel::abort("Error reading global properties:\n".red + error.to_s)
end #contracts
end # Token
end # SCC

############################################################ {{{1 ###########
# vim: set nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab :
# vim: set textwidth=0 filetype=ruby foldmethod=marker nospell :
# vim: set spell spelllang=en_gb fileencoding=utf-8 :
28 changes: 28 additions & 0 deletions Utilities/Test-Steem-Engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/opt/local/bin/ruby
############################################################# {{{1 ##########
# Copyright © 2019 Martin Krischik «krischik@users.sourceforge.net»
#############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see «http://www.gnu.org/licenses/».
############################################################# }}}1 ##########

require_relative '../Scripts/SCC/Contract'

_tokens = SCC::Contract.new "tokens"

pp _tokens

############################################################ {{{1 ###########
# vim: set nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab :
# vim: set textwidth=0 filetype=ruby foldmethod=marker nospell :
# vim: set spell spelllang=en_gb fileencoding=utf-8 :

0 comments on commit ce360e1

Please sign in to comment.