Module: TonSdk::Abi

Defined in:
lib/ton_sdk_client/abi.rb

Defined Under Namespace

Classes: Abi, AbiContract, AbiData, AbiEvent, AbiFunction, AbiParam, DecodedMessageBody, Signer

Constant Summary collapse

FunctionHeader =
KwStruct.new(:expire, :time, :pubkey)
CallSet =
KwStruct.new(:function_name, :header, :input) do
  def initialize(function_name:, header: nil, input: nil)
    super
  end

  def to_h
    {
      function_name: function_name,
      header: header.to_h,
      input: input
    }
  end
end
DeploySet =
KwStruct.new(:tvc, :workchain_id, :initial_data, :initial_pubkey) do
  def initialize(tvc:, workchain_id: nil, initial_data: nil, initial_pubkey: nil)
    super
  end
end
STATIC_INIT_SOURCE_TYPES =
[:message, :state_init, :tvc]
StateInitSource =

TODO: Refactor with subclasses?

KwStruct.new(
  :type,
  :source,
  :code,
  :data,
  :library,
  :tvc,
  :public_key,
  :init_params
) do
  def initialize(
    type:,
    source: nil,
    code: nil,
    data: nil,
    library: nil,
    tvc: nil,
    public_key: nil,
    init_params: nil
  )
    unless STATIC_INIT_SOURCE_TYPES.include?(type)
      raise ArgumentError.new("unknown type: #{type}; known types: #{STATIC_INIT_SOURCE_TYPES}")
    end
    super
  end

  def to_h
    h1 = {
      type: Helper.sym_to_capitalized_case_str(type)
    }

    h2 = case type
    when :message
      {
        source: source.to_h
      }
    when :state_init
      {
        code: code,
        data: data,
        library: library
      }
    when :tvc
      {
        public_key: public_key,
        init_params: init_params.to_h
      }
    else
      raise ArgumentError.new("unknown type: #{type}; known types: #{STATIC_INIT_SOURCE_TYPES}")
    end

    h1.merge(h2)
  end
end
StateInitParams =
KwStruct.new(:abi, :value) do
  def initialize(abi:, value:)
    super
  end
end
MESSAGE_SOURCE_TYPES =
[:encoded, :encoding_params]
MessageSource =
KwStruct.new(
  :type,
  :message,
  :abi,
  :address,
  :deploy_set,
  :call_set,
  :signer,
  :processing_try_index
) do
  def initialize(
    type:,
    message: nil,
    abi:  nil,
    address: nil,
    deploy_set: nil,
    call_set: nil,
    signer:  nil,
    processing_try_index: 0
  )
    unless MESSAGE_SOURCE_TYPES.include?(type)
      raise ArgumentError.new("unknown type: #{type}; known types: #{MESSAGE_SOURCE_TYPES}")
    end

    super
  end

  def to_h
    h1 = {
      type: Helper.sym_to_capitalized_case_str(type)
    }

    h2 = case type
    when :encoded
      {
        message: message,
        abi: abi&.to_h
      }
    when :encoding_params
      {
        abi: abi.to_h,
        address: address,
        deploy_set: deploy_set&.to_h,
        call_set: call_set&.to_h,
        signer: signer&.to_h,
        processing_try_index: processing_try_index
      }
    end

    h1.merge(h2)
  end
end
ParamsOfEncodeMessageBody =
KwStruct.new(
  :abi,
  :call_set,
  :is_internal,
  :signer,
  :processing_try_index
) do
  def to_h
    {
      abi: abi.to_h,
      call_set: call_set.to_h,
      is_internal: is_internal,
      signer: signer.to_h,
      processing_try_index: processing_try_index
    }
  end
end
ResultOfEncodeMessageBody =
KwStruct.new(:body, :data_to_sign) do
  def initialize(body:, data_to_sign: nil)
    super
  end
end
ParamsOfAttachSignatureToMessageBody =
KwStruct.new(:abi, :public_key, :message, :signature) do
  def to_h
    {
      abi: abi.to_h,
      public_key: public_key,
      message: message,
      signature: signature
    }
  end
end
ResultOfAttachSignatureToMessageBody =
KwStruct.new(:body)
ParamsOfEncodeMessage =
KwStruct.new(
  :abi,
  :address,
  :deploy_set,
  :call_set,
  :signer,
  :processing_try_index
) do
  def initialize(
    abi:,
    address: nil,
    deploy_set: nil,
    call_set: nil,
    signer:,
    processing_try_index: 0
  )
    super
  end

  def to_h
    {
      abi: abi.to_h,
      address: address,
      deploy_set: deploy_set&.to_h,
      call_set: call_set&.to_h,
      signer: signer.to_h,
      processing_try_index: processing_try_index
    }
  end
end
ResultOfEncodeMessage =
KwStruct.new(:message, :data_to_sign, :address, :message_id) do
  def initialize(message:, data_to_sign: nil, address:, message_id:)
    super
  end
end
ParamsOfAttachSignature =
KwStruct.new(:abi, :public_key, :message, :signature) do
  def initialize(abi:, public_key:, message:, signature:)
    super
  end

  def to_h
    {
      abi: abi&.to_h,
      public_key: public_key,
      message: message,
      signature: signature
    }
  end
end
ResultOfAttachSignature =
KwStruct.new(:message, :message_id) do
  def initialize(message:, message_id:)
    super
  end
end
ParamsOfDecodeMessage =
KwStruct.new(:abi, :message, :allow_partial) do
  def initialize(abi:, message:, allow_partial: false)
    super
  end

  def to_h
    {
      abi: abi&.to_h,
      message: message,
      allow_partial: allow_partial
    }
  end
end
ParamsOfDecodeMessageBody =
KwStruct.new(:abi, :body, :is_internal, :allow_partial) do
  def initialize(abi:, body:, is_internal:, allow_partial: false)
    super
  end

  def to_h
    {
      abi: abi&.to_h,
      body: body,
      is_internal: is_internal,
      allow_partial: allow_partial
    }
  end
end
ParamsOfEncodeAccount =
KwStruct.new(
  :state_init,
  :balance,
  :last_trans_lt,
  :last_paid,
  :boc_cache
) do
  def to_h
    {
      state_init: state_init.to_h,
      balance: balance,
      last_trans_lt: last_trans_lt,
      last_paid: last_paid,
      boc_cache: boc_cache&.to_h
    }
  end
end
ResultOfEncodeAccount =
KwStruct.new(:account, :id_) do
  def initialize(account:, id_:)
    super
  end
end
ParamsOfEncodeInternalMessage =
KwStruct.new(
  :abi,
  :address,
  :src_address,
  :deploy_set,
  :call_set,
  :value,
  :bounce,
  :enable_ihr
) do
  def initialize(
    abi: nil,
    address: nil,
    src_address: nil,
    deploy_set: nil,
    call_set: nil,
    value:,
    bounce: nil,
    enable_ihr: nil
  )
    super
  end
end
ResultOfEncodeInternalMessage =
KwStruct.new(
  :message,
  :address,
  :message_id
) do
  def initialize(message:, address:, message_id:)
    super
  end
end
ParamsOfDecodeAccountData =
KwStruct.new(:abi, :data, :allow_partial) do
  def initialize(abi:, data:, allow_partial: false)
    super
  end

  def to_h
    {
      abi: abi&.to_h,
      data: data,
      allow_partial: allow_partial
    }
  end
end
ResultOfDecodeAccountData =
KwStruct.new(:data)
ParamsOfUpdateInitialData =
KwStruct.new(
  :data,
  :abi,
  :initial_data,
  :initial_pubkey,
  :boc_cache
) do
  def to_h
    {
      data: data,
      abi: abi&.to_h,
      initial_data: initial_data,
      initial_pubkey: initial_pubkey,
      boc_cache: boc_cache&.to_h
    }
  end
end
ResultOfUpdateInitialData =
KwStruct.new(:data)
ParamsOfEncodeInitialData =
KwStruct.new(:abi, :initial_data, :initial_pubkey, :boc_cache) do
  def to_h
    {
      abi: abi&.to_h,
      initial_data: initial_data,
      initial_pubkey: initial_pubkey,
      boc_cache: boc_cache&.to_h
    }
  end
end
ResultOfEncodeInitialData =
KwStruct.new(:data)
ParamsOfDecodeInitialData =
KwStruct.new(:data, :abi, :allow_partial) do
  def initialize(data:, abi:, allow_partial: false)
    super
  end

  def to_h
    {
      data: data,
      abi: abi&.to_h,
      allow_partial: allow_partial
    }
  end
end
ResultOfDecodeInitialData =
KwStruct.new(:initial_pubkey, :initial_data)
ParamsOfDecodeBoc =
KwStruct.new(:params, :boc, :allow_partial) do
  def to_h
    {
      params: params&.map(&:to_h),
      boc: boc,
      allow_partial: allow_partial
    }
  end
end
ResultOfDecodeBoc =
KwStruct.new(:data)
ParamsOfAbiEncodeBoc =
KwStruct.new(:params, :data, :boc_cache) do
  def to_h
    {
      params: params&.map(&:to_h),
      data: data,
      boc_cache: boc_cache&.to_h
    }
  end
end
ResultOfAbiEncodeBoc =
KwStruct.new(:boc)

Class Method Summary collapse

Class Method Details

.attach_signature(ctx, params) ⇒ Object



866
867
868
869
870
871
872
873
874
875
876
877
878
# File 'lib/ton_sdk_client/abi.rb', line 866

def self.attach_signature(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.attach_signature", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfAttachSignature.new(
          message: resp.result["message"],
          message_id: resp.result["message_id"])
      )
    else
      yield resp
    end
  end
end

.attach_signature_to_message_body(ctx, params) ⇒ Object



837
838
839
840
841
842
843
844
845
846
847
# File 'lib/ton_sdk_client/abi.rb', line 837

def self.attach_signature_to_message_body(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.attach_signature_to_message_body", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfAttachSignatureToMessageBody.new(body: resp.result["body"])
      )
    else
      yield resp
    end
  end
end

.decode_account_data(ctx, params) ⇒ Object



935
936
937
938
939
940
941
942
943
944
945
946
947
# File 'lib/ton_sdk_client/abi.rb', line 935

def self.(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.decode_account_data", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfDecodeAccountData.new(
          data: resp.result["data"]
        )
      )
    else
      yield resp
    end
  end
end

.decode_boc(ctx, params) ⇒ Object



992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
# File 'lib/ton_sdk_client/abi.rb', line 992

def self.decode_boc(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.decode_boc", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfDecodeBoc.new(
          data: resp.result["data"]
        )
      )
    else
      yield resp
    end
  end
end

.decode_initial_data(ctx, params) ⇒ Object



977
978
979
980
981
982
983
984
985
986
987
988
989
990
# File 'lib/ton_sdk_client/abi.rb', line 977

def self.decode_initial_data(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.decode_initial_data", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfDecodeInitialData.new(
          initial_pubkey: resp.result["initial_pubkey"],
          initial_data: resp.result["initial_data"]
        )
      )
    else
      yield resp
    end
  end
end

.decode_message(ctx, params) ⇒ Object



880
881
882
883
884
885
886
887
888
889
890
# File 'lib/ton_sdk_client/abi.rb', line 880

def self.decode_message(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.decode_message", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: DecodedMessageBody.from_json(resp.result)
      )
    else
      yield resp
    end
  end
end

.decode_message_body(ctx, params) ⇒ Object



892
893
894
895
896
897
898
899
900
901
902
# File 'lib/ton_sdk_client/abi.rb', line 892

def self.decode_message_body(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.decode_message_body", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: DecodedMessageBody.from_json(resp.result)
      )
    else
      yield resp
    end
  end
end

.encode_account(ctx, params) ⇒ Object



904
905
906
907
908
909
910
911
912
913
914
915
916
917
# File 'lib/ton_sdk_client/abi.rb', line 904

def self.(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.encode_account", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfEncodeAccount.new(
          account: resp.result["account"],
          id_: resp.result["id"]
        )
      )
    else
      yield resp
    end
  end
end

.encode_boc(ctx, params) ⇒ Object



1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
# File 'lib/ton_sdk_client/abi.rb', line 1006

def self.encode_boc(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.encode_boc", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfAbiEncodeBoc.new(
          boc: resp.result["boc"]
        )
      )
    else
      yield resp
    end
  end
end

.encode_initial_data(ctx, params) ⇒ Object



963
964
965
966
967
968
969
970
971
972
973
974
975
# File 'lib/ton_sdk_client/abi.rb', line 963

def self.encode_initial_data(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.encode_initial_data", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfEncodeInitialData.new(
          data: resp.result["data"]
        )
      )
    else
      yield resp
    end
  end
end

.encode_internal_message(ctx, params) ⇒ Object



919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
# File 'lib/ton_sdk_client/abi.rb', line 919

def self.encode_internal_message(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.encode_internal_message", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfEncodeInternalMessage.new(
          message: resp.result["message"],
          address: resp.result["address"],
          message_id: resp.result["message_id"]
        )
      )
    else
      yield resp
    end
  end
end

.encode_message(ctx, params) ⇒ Object



849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
# File 'lib/ton_sdk_client/abi.rb', line 849

def self.encode_message(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.encode_message", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfEncodeMessage.new(
          message: resp.result["message"],
          data_to_sign: resp.result["data_to_sign"],
          address: resp.result["address"],
          message_id: resp.result["message_id"]
        )
      )
    else
      yield resp
    end
  end
end

.encode_message_body(ctx, params) ⇒ Object

functions



823
824
825
826
827
828
829
830
831
832
833
834
835
# File 'lib/ton_sdk_client/abi.rb', line 823

def self.encode_message_body(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.encode_message_body", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfEncodeMessageBody.new(
          body: resp.result["body"],
          data_to_sign: resp.result["data_to_sign"])
        )
    else
      yield resp
    end
  end
end

.update_initial_data(ctx, params) ⇒ Object



949
950
951
952
953
954
955
956
957
958
959
960
961
# File 'lib/ton_sdk_client/abi.rb', line 949

def self.update_initial_data(ctx, params)
  Interop::request_to_native_lib(ctx, "abi.update_initial_data", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfUpdateInitialData.new(
          data: resp.result["data"]
        )
      )
    else
      yield resp
    end
  end
end