Class: MandateClaw::DSL::Contract

Inherits:
Object
  • Object
show all
Defined in:
lib/mandate_claw/dsl/contract.rb

Overview

Base class for all MandateClaw contracts.

Usage:

class InvoiceContract < MandateClaw::DSL::Contract
  contract do
    party :buyer,    identifies_by: :customer_id
    party :seller,   identifies_by: :merchant_id
    party :ai_agent, identifies_by: :agent_did, kind: :autonomous

    obligation :pay_invoice, on: :buyer, within: 30.days, breach: :late_payment_penalty
    permission :dispute,     on: :buyer, within: 7.days,  event: :raise_dispute
    prohibition :unilateral_amend, on: :ai_agent, breach: :void_transition

    agent_bounds :ai_agent do
      may        :issue_invoice, :send_reminder
      must_not   :modify_amount, :waive_penalty
      must_log_to :contract_registry
    end

    attestation do
      require_signature_from :buyer, :seller, :ai_agent
      sign_with :ed25519
    end
  end
end

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

._agent_boundsObject (readonly)

Returns the value of attribute _agent_bounds.



36
37
38
# File 'lib/mandate_claw/dsl/contract.rb', line 36

def _agent_bounds
  @_agent_bounds
end

._attestationObject (readonly)

Returns the value of attribute _attestation.



36
37
38
# File 'lib/mandate_claw/dsl/contract.rb', line 36

def _attestation
  @_attestation
end

._contract_nameObject (readonly)

Returns the value of attribute _contract_name.



36
37
38
# File 'lib/mandate_claw/dsl/contract.rb', line 36

def _contract_name
  @_contract_name
end

._obligationsObject (readonly)

Returns the value of attribute _obligations.



36
37
38
# File 'lib/mandate_claw/dsl/contract.rb', line 36

def _obligations
  @_obligations
end

._partiesObject (readonly)

Returns the value of attribute _parties.



36
37
38
# File 'lib/mandate_claw/dsl/contract.rb', line 36

def _parties
  @_parties
end

._permissionsObject (readonly)

Returns the value of attribute _permissions.



36
37
38
# File 'lib/mandate_claw/dsl/contract.rb', line 36

def _permissions
  @_permissions
end

._prohibitionsObject (readonly)

Returns the value of attribute _prohibitions.



36
37
38
# File 'lib/mandate_claw/dsl/contract.rb', line 36

def _prohibitions
  @_prohibitions
end

._rulesObject (readonly)

Returns the value of attribute _rules.



36
37
38
# File 'lib/mandate_claw/dsl/contract.rb', line 36

def _rules
  @_rules
end

Class Method Details

.autonomous_partiesObject



62
63
64
# File 'lib/mandate_claw/dsl/contract.rb', line 62

def autonomous_parties
  _parties.select { |_, p| p.kind == :autonomous }.keys
end

.contract(name = nil, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mandate_claw/dsl/contract.rb', line 40

def contract(name = nil, &block)
  @_contract_name  = name || self.name&.underscore&.to_sym || :unnamed
  @_parties        = {}
  @_obligations    = []
  @_permissions    = []
  @_prohibitions   = []
  @_agent_bounds   = {}
  @_attestation    = nil
  @_rules          = []

  DSL::ContractBuilder.new(self).instance_eval(&block) if block_given?
  self
end

.to_markdownObject



58
59
60
# File 'lib/mandate_claw/dsl/contract.rb', line 58

def to_markdown
  MandateClaw::Renderers::MarkdownRenderer.new(self).render
end

.validate!Object



54
55
56
# File 'lib/mandate_claw/dsl/contract.rb', line 54

def validate!
  MandateClaw::Validators::ContractValidator.new(self).validate!
end