Class: Casper::Entity::DeployService
- Inherits:
-
Object
- Object
- Casper::Entity::DeployService
- Defined in:
- lib/entity/deploy.rb
Overview
Class that enable to make a deploy
Instance Attribute Summary collapse
-
#approvals ⇒ Object
Returns the value of attribute approvals.
-
#deploy ⇒ Object
Returns the value of attribute deploy.
-
#deploy_hash(deploy_header) ⇒ String
Compute deploy hash.
-
#header ⇒ Object
Returns the value of attribute header.
-
#payment ⇒ Object
Returns the value of attribute payment.
-
#session ⇒ Object
Returns the value of attribute session.
Instance Method Summary collapse
-
#add_approval(approvals, approval) ⇒ Array<DeployApproval>
The approval list of Deploy.
-
#deploy_body_hash(payment, session) ⇒ String
Compute body hash.
-
#get_approvals ⇒ Array<DeployApproval>
The approval list of Deploy.
-
#initialize ⇒ DeployService
constructor
A new instance of DeployService.
- #make_deploy(deploy_hash, header, payment, session, approvals) ⇒ Deploy
-
#sign_deploy(deploy, key_pair) ⇒ Deploy
The Deploy object.
-
#update_header_body_hash(body_hash) ⇒ String
The body hash of Deploy header.
-
#validate_deploy?(deploy) ⇒ Boolean
Validate Deploy.
Constructor Details
#initialize ⇒ DeployService
Returns a new instance of DeployService.
76 77 78 79 80 81 82 83 84 |
# File 'lib/entity/deploy.rb', line 76 def initialize() @deploy_hash = "" @header = Casper::Entity::DeployHeader.new(h = {}) @body_hash = "" @payment = {} @session = {} @approvals = [] @deploy = Deploy.new(nil, nil, nil, nil, nil) end |
Instance Attribute Details
#approvals ⇒ Object
Returns the value of attribute approvals.
75 76 77 |
# File 'lib/entity/deploy.rb', line 75 def approvals @approvals end |
#deploy ⇒ Object
Returns the value of attribute deploy.
75 76 77 |
# File 'lib/entity/deploy.rb', line 75 def deploy @deploy end |
#deploy_hash(deploy_header) ⇒ String
Compute deploy hash
136 137 138 |
# File 'lib/entity/deploy.rb', line 136 def deploy_hash @deploy_hash end |
#header ⇒ Object
Returns the value of attribute header.
75 76 77 |
# File 'lib/entity/deploy.rb', line 75 def header @header end |
#payment ⇒ Object
Returns the value of attribute payment.
75 76 77 |
# File 'lib/entity/deploy.rb', line 75 def payment @payment end |
#session ⇒ Object
Returns the value of attribute session.
75 76 77 |
# File 'lib/entity/deploy.rb', line 75 def session @session end |
Instance Method Details
#add_approval(approvals, approval) ⇒ Array<DeployApproval>
Returns the approval list of Deploy.
150 151 152 |
# File 'lib/entity/deploy.rb', line 150 def add_approval(approvals, approval) @approvals << approval end |
#deploy_body_hash(payment, session) ⇒ String
Compute body hash
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/entity/deploy.rb', line 105 def deploy_body_hash(payment, session) # puts "Deploy::deploy_body_hash is called" if payment != nil && session != nil payment_serializer = DeployExecutable.new(payment) payment_byte_array = payment_serializer.to_bytes # puts payment_serializer.module_bytes? # puts payment_serializer.module_bytes # puts payment_serializer.module_bytes.get_args session_serializer = DeployExecutable.new(session) session_byte_array = session_serializer.to_bytes arr = payment_byte_array.concat(session_byte_array) hex = Utils::ByteUtils.byte_array_to_hex(arr) # puts "body_serializer:" # puts Utils::ByteUtils.byte_array_to_hex(arr) len = 32 key = Blake2b::Key.none Blake2b.hex(hex, key, len) @body_hash = "42751eb696c9ed4d11715f03fe8e053065ce671991d808b6870e2a1e49fe356c" end end |
#get_approvals ⇒ Array<DeployApproval>
Returns the approval list of Deploy.
155 156 157 |
# File 'lib/entity/deploy.rb', line 155 def get_approvals @approvals end |
#make_deploy(deploy_hash, header, payment, session, approvals) ⇒ Deploy
92 93 94 95 96 97 98 99 100 |
# File 'lib/entity/deploy.rb', line 92 def make_deploy(deploy_hash, header, payment, session, approvals) @header = Casper::Entity::DeployHeader.new(header) @payment = payment @session = session @body_hash = deploy_body_hash(payment, session) @header.set_body_hash(@body_hash) @deploy_hash = deploy_hash(@header) @deploy = Deploy.new(@deploy_hash, @header.to_hash, @payment, @session, approvals) end |
#sign_deploy(deploy, key_pair) ⇒ Deploy
Returns the Deploy object.
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/entity/deploy.rb', line 164 def sign_deploy(deploy, key_pair) public_key = deploy.get_header[:account] signature = key_pair.sign(deploy.get_hash) # puts "Signer = #{signature}" signer = public_key approval = { "signer": signer, "signature": signature } deploy.add_approval(approval) deploy.to_hash end |
#update_header_body_hash(body_hash) ⇒ String
Returns the body hash of Deploy header.
128 129 130 |
# File 'lib/entity/deploy.rb', line 128 def update_header_body_hash(body_hash) @header.set_body_hash(body_hash) end |
#validate_deploy?(deploy) ⇒ Boolean
Validate Deploy
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/entity/deploy.rb', line 181 def validate_deploy?(deploy) payment_serializer = DeployExecutable.new(deploy.get_payment) payment_byte_array = payment_serializer.to_bytes session_serializer = DeployExecutable.new(deploy.get_session) session_byte_array = session_serializer.to_bytes arr = payment_byte_array.concat(session_byte_array) hex = Utils::ByteUtils.byte_array_to_hex(arr) false unless @body_hash == deploy.get_header[:body_hash] && deploy.get_hash == @deploy_hash puts deploy.get_hash true # false unless @body_hash == Blake2b(hex) && deploy.get_hash == @deploy_hash # true end |