require 'ffi'
module Glsdk
def self.uniffi_in_range(i, type_name, min, max)
raise TypeError, "no implicit conversion of #{i} into Integer" unless i.respond_to?(:to_int)
i = i.to_int
raise RangeError, "#{type_name} requires #{min} <= value < #{max}" unless (min <= i && i < max)
i
end
def self.uniffi_utf8(v)
raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
v = v.to_str.encode(Encoding::UTF_8)
raise Encoding::InvalidByteSequenceError, "not a valid UTF-8 encoded string" unless v.valid_encoding?
v
end
def self.uniffi_bytes(v)
raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
v.to_str
end
class RustBuffer < FFI::Struct
layout :capacity, :uint64,
:len, :uint64,
:data, :pointer
def self.alloc(size)
return Glsdk.rust_call(:ffi_glsdk_rustbuffer_alloc, size)
end
def self.reserve(rbuf, additional)
return Glsdk.rust_call(:ffi_glsdk_rustbuffer_reserve, rbuf, additional)
end
def free
Glsdk.rust_call(:ffi_glsdk_rustbuffer_free, self)
end
def capacity
self[:capacity]
end
def len
self[:len]
end
def len=(value)
self[:len] = value
end
def data
self[:data]
end
def to_s
"RustBuffer(capacity=#{capacity}, len=#{len}, data=#{data.read_bytes len})"
end
def self.allocWithBuilder
builder = RustBufferBuilder.new
begin
yield builder
rescue => e
builder.discard
raise e
end
end
def consumeWithStream
stream = RustBufferStream.new self
yield stream
raise RuntimeError, 'junk data left in buffer after consuming' if stream.remaining != 0
ensure
free
end
def self.allocFromString(value)
RustBuffer.allocWithBuilder do |builder|
builder.write value.encode('utf-8')
return builder.finalize
end
end
def consumeIntoString
consumeWithStream do |stream|
return stream.read(stream.remaining).force_encoding(Encoding::UTF_8)
end
end
def self.allocFromBytes(value)
RustBuffer.allocWithBuilder do |builder|
builder.write_Bytes(value)
return builder.finalize
end
end
def consumeIntoBytes
consumeWithStream do |stream|
return stream.readBytes
end
end
def self.check_lower_TypeNetwork(v)
end
def self.alloc_from_TypeNetwork(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_TypeNetwork(v)
return builder.finalize
end
end
def consumeIntoTypeNetwork
consumeWithStream do |stream|
return stream.readTypeNetwork
end
end
def self.check_lower_TypePayStatus(v)
end
def self.alloc_from_TypePayStatus(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_TypePayStatus(v)
return builder.finalize
end
end
def consumeIntoTypePayStatus
consumeWithStream do |stream|
return stream.readTypePayStatus
end
end
def self.check_lower_Optionalu64(v)
if not v.nil?
end
end
def self.alloc_from_Optionalu64(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_Optionalu64(v)
return builder.finalize()
end
end
def consumeIntoOptionalu64
consumeWithStream do |stream|
return stream.readOptionalu64
end
end
def self.check_lower_Optionalstring(v)
if not v.nil?
end
end
def self.alloc_from_Optionalstring(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_Optionalstring(v)
return builder.finalize()
end
end
def consumeIntoOptionalstring
consumeWithStream do |stream|
return stream.readOptionalstring
end
end
def self.check_lower_MapStringString(v)
v.each do |k, v|
end
end
def self.alloc_from_MapStringString(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_MapStringString(v)
return builder.finalize
end
end
def consumeIntoMapStringString
consumeWithStream do |stream|
return stream.readMapStringString
end
end
end
module UniFFILib
class ForeignBytes < FFI::Struct
layout :len, :int32,
:data, :pointer
def len
self[:len]
end
def data
self[:data]
end
def to_s
"ForeignBytes(len=#{len}, data=#{data.read_bytes(len)})"
end
end
end
private_constant :UniFFILib
class RustBufferStream
def initialize(rbuf)
@rbuf = rbuf
@offset = 0
end
def remaining
@rbuf.len - @offset
end
def read(size)
raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
data = @rbuf.data.get_bytes @offset, size
@offset += size
data
end
def readI32
unpack_from 4, 'l>'
end
def readU64
unpack_from 8, 'Q>'
end
def readString
size = unpack_from 4, 'l>'
raise InternalError, 'Unexpected negative string length' if size.negative?
read(size).force_encoding(Encoding::UTF_8)
end
def readBytes
size = unpack_from 4, 'l>'
raise InternalError, 'Unexpected negative byte string length' if size.negative?
read(size).force_encoding(Encoding::BINARY)
end
def readTypeCredentials
pointer = FFI::Pointer.new unpack_from 8, 'Q>'
return Credentials.uniffi_allocate(pointer)
end
def readTypeHandle
pointer = FFI::Pointer.new unpack_from 8, 'Q>'
return Handle.uniffi_allocate(pointer)
end
def readTypeNode
pointer = FFI::Pointer.new unpack_from 8, 'Q>'
return Node.uniffi_allocate(pointer)
end
def readTypeOnchainReceiveResponse
pointer = FFI::Pointer.new unpack_from 8, 'Q>'
return OnchainReceiveResponse.uniffi_allocate(pointer)
end
def readTypeOnchainSendResponse
pointer = FFI::Pointer.new unpack_from 8, 'Q>'
return OnchainSendResponse.uniffi_allocate(pointer)
end
def readTypeReceiveResponse
pointer = FFI::Pointer.new unpack_from 8, 'Q>'
return ReceiveResponse.uniffi_allocate(pointer)
end
def readTypeScheduler
pointer = FFI::Pointer.new unpack_from 8, 'Q>'
return Scheduler.uniffi_allocate(pointer)
end
def readTypeSendResponse
pointer = FFI::Pointer.new unpack_from 8, 'Q>'
return SendResponse.uniffi_allocate(pointer)
end
def readTypeSigner
pointer = FFI::Pointer.new unpack_from 8, 'Q>'
return Signer.uniffi_allocate(pointer)
end
def readTypeError
variant = unpack_from 4, 'l>'
if variant == 1
return Error::DuplicateNode.new(
readI32(),
readString(),
readMapStringString()
)
end
if variant == 2
return Error::NoSuchNode.new(
readI32(),
readString(),
readMapStringString()
)
end
if variant == 3
return Error::UnparseableCreds.new(
readI32(),
readString(),
readMapStringString()
)
end
if variant == 4
return Error::PhraseCorrupted.new(
readI32(),
readString(),
readMapStringString()
)
end
if variant == 5
return Error::Rpc.new(
readI32(),
readString(),
readMapStringString()
)
end
if variant == 6
return Error::Argument.new(
readI32(),
readString(),
readMapStringString()
)
end
if variant == 7
return Error::Other.new(
readI32(),
readString(),
readMapStringString()
)
end
raise InternalError, 'Unexpected variant tag for TypeError'
end
def readTypeNetwork
variant = unpack_from 4, 'l>'
if variant == 1
return Network::BITCOIN
end
if variant == 2
return Network::REGTEST
end
raise InternalError, 'Unexpected variant tag for TypeNetwork'
end
def readTypePayStatus
variant = unpack_from 4, 'l>'
if variant == 1
return PayStatus::COMPLETE
end
if variant == 2
return PayStatus::PENDING
end
if variant == 3
return PayStatus::FAILED
end
raise InternalError, 'Unexpected variant tag for TypePayStatus'
end
def readOptionalu64
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readU64
else
raise InternalError, 'Unexpected flag byte for Optionalu64'
end
end
def readOptionalstring
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readString
else
raise InternalError, 'Unexpected flag byte for Optionalstring'
end
end
def readMapStringString
count = unpack_from 4, 'l>'
raise InternalError, 'Unexpected negative map size' if count.negative?
items = {}
count.times do
key = readString
items[key] = readString
end
items
end
def unpack_from(size, format)
raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
value = @rbuf.data.get_bytes(@offset, size).unpack format
@offset += size
raise 'more than one element!!!' if value.size > 1
value[0]
end
end
private_constant :RustBufferStream
class RustBufferBuilder
def initialize
@rust_buf = RustBuffer.alloc 16
@rust_buf.len = 0
end
def finalize
rbuf = @rust_buf
@rust_buf = nil
rbuf
end
def discard
return if @rust_buf.nil?
rbuf = finalize
rbuf.free
end
def write(value)
reserve(value.bytes.size) do
@rust_buf.data.put_array_of_char @rust_buf.len, value.bytes
end
end
def write_I32(v)
v = Glsdk::uniffi_in_range(v, "i32", -2**31, 2**31)
pack_into(4, 'l>', v)
end
def write_U64(v)
v = Glsdk::uniffi_in_range(v, "u64", 0, 2**64)
pack_into(8, 'Q>', v)
end
def write_String(v)
v = Glsdk::uniffi_utf8(v)
pack_into 4, 'l>', v.bytes.size
write v
end
def write_Bytes(v)
v = Glsdk::uniffi_bytes(v)
pack_into 4, 'l>', v.bytes.size
write v
end
def write_TypeCredentials(obj)
pointer = Credentials.uniffi_lower obj
pack_into(8, 'Q>', pointer.address)
end
def write_TypeHandle(obj)
pointer = Handle.uniffi_lower obj
pack_into(8, 'Q>', pointer.address)
end
def write_TypeNode(obj)
pointer = Node.uniffi_lower obj
pack_into(8, 'Q>', pointer.address)
end
def write_TypeOnchainReceiveResponse(obj)
pointer = OnchainReceiveResponse.uniffi_lower obj
pack_into(8, 'Q>', pointer.address)
end
def write_TypeOnchainSendResponse(obj)
pointer = OnchainSendResponse.uniffi_lower obj
pack_into(8, 'Q>', pointer.address)
end
def write_TypeReceiveResponse(obj)
pointer = ReceiveResponse.uniffi_lower obj
pack_into(8, 'Q>', pointer.address)
end
def write_TypeScheduler(obj)
pointer = Scheduler.uniffi_lower obj
pack_into(8, 'Q>', pointer.address)
end
def write_TypeSendResponse(obj)
pointer = SendResponse.uniffi_lower obj
pack_into(8, 'Q>', pointer.address)
end
def write_TypeSigner(obj)
pointer = Signer.uniffi_lower obj
pack_into(8, 'Q>', pointer.address)
end
def write_TypeNetwork(v)
pack_into(4, 'l>', v)
end
def write_TypePayStatus(v)
pack_into(4, 'l>', v)
end
def write_Optionalu64(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_U64(v)
end
end
def write_Optionalstring(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_String(v)
end
end
def write_MapStringString(items)
pack_into(4, 'l>', items.size)
items.each do |k, v|
write_String(k)
self.write_String(v)
end
end
private
def reserve(num_bytes)
if @rust_buf.len + num_bytes > @rust_buf.capacity
@rust_buf = RustBuffer.reserve(@rust_buf, num_bytes)
end
yield
@rust_buf.len += num_bytes
end
def pack_into(size, format, value)
reserve(size) do
@rust_buf.data.put_array_of_char @rust_buf.len, [value].pack(format).bytes
end
end
end
private_constant :RustBufferBuilder
class RustCallStatus < FFI::Struct
layout :code, :int8,
:error_buf, RustBuffer
def code
self[:code]
end
def error_buf
self[:error_buf]
end
def to_s
"RustCallStatus(code=#{self[:code]})"
end
end
CALL_SUCCESS = 0
CALL_ERROR = 1
CALL_PANIC = 2
module Error
class DuplicateNode < StandardError
def initialize(code, message, values)
@code = code
@message = message
@values = values
super()
end
attr_reader :code, :message, :values
def to_s
"#{self.class.name}(code=#{@code.inspect}, message=#{@message.inspect}, values=#{@values.inspect})"
end
end
class NoSuchNode < StandardError
def initialize(code, message, values)
@code = code
@message = message
@values = values
super()
end
attr_reader :code, :message, :values
def to_s
"#{self.class.name}(code=#{@code.inspect}, message=#{@message.inspect}, values=#{@values.inspect})"
end
end
class UnparseableCreds < StandardError
def initialize(code, message, values)
@code = code
@message = message
@values = values
super()
end
attr_reader :code, :message, :values
def to_s
"#{self.class.name}(code=#{@code.inspect}, message=#{@message.inspect}, values=#{@values.inspect})"
end
end
class PhraseCorrupted < StandardError
def initialize(code, message, values)
@code = code
@message = message
@values = values
super()
end
attr_reader :code, :message, :values
def to_s
"#{self.class.name}(code=#{@code.inspect}, message=#{@message.inspect}, values=#{@values.inspect})"
end
end
class Rpc < StandardError
def initialize(code, message, values)
@code = code
@message = message
@values = values
super()
end
attr_reader :code, :message, :values
def to_s
"#{self.class.name}(code=#{@code.inspect}, message=#{@message.inspect}, values=#{@values.inspect})"
end
end
class Argument < StandardError
def initialize(code, message, values)
@code = code
@message = message
@values = values
super()
end
attr_reader :code, :message, :values
def to_s
"#{self.class.name}(code=#{@code.inspect}, message=#{@message.inspect}, values=#{@values.inspect})"
end
end
class Other < StandardError
def initialize(code, message, values)
@code = code
@message = message
@values = values
super()
end
attr_reader :code, :message, :values
def to_s
"#{self.class.name}(code=#{@code.inspect}, message=#{@message.inspect}, values=#{@values.inspect})"
end
end
end
ERROR_MODULE_TO_READER_METHOD = {
Error => :readTypeError,
}
private_constant :ERROR_MODULE_TO_READER_METHOD, :CALL_SUCCESS, :CALL_ERROR, :CALL_PANIC,
:RustCallStatus
def self.consume_buffer_into_error(error_module, rust_buffer)
rust_buffer.consumeWithStream do |stream|
reader_method = ERROR_MODULE_TO_READER_METHOD[error_module]
return stream.send(reader_method)
end
end
class InternalError < StandardError
end
def self.rust_call(fn_name, *args)
rust_call_with_error(nil, fn_name, *args)
end
def self.rust_call_with_error(error_module, fn_name, *args)
status = RustCallStatus.new
args << status
result = UniFFILib.public_send(fn_name, *args)
case status.code
when CALL_SUCCESS
result
when CALL_ERROR
if error_module.nil?
status.error_buf.free
raise InternalError, "CALL_ERROR with no error_module set"
else
raise consume_buffer_into_error(error_module, status.error_buf)
end
when CALL_PANIC
if status.error_buf.len > 0
raise InternalError, status.error_buf.consumeIntoString()
else
raise InternalError, "Rust panic"
end
else
raise InternalError, "Unknown call status: #{status.code}"
end
end
private_class_method :consume_buffer_into_error
module UniFFILib
extend FFI::Library
ffi_lib 'glsdk'
attach_function :uniffi_glsdk_fn_clone_credentials,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_free_credentials,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_glsdk_fn_constructor_credentials_load,
[RustBuffer.by_value, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_method_credentials_save,
[:pointer, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_glsdk_fn_clone_handle,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_free_handle,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_glsdk_fn_method_handle_stop,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_glsdk_fn_clone_node,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_free_node,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_glsdk_fn_constructor_node_new,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_method_node_onchain_receive,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_method_node_onchain_send,
[:pointer, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_method_node_receive,
[:pointer, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_method_node_send,
[:pointer, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_method_node_stop,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_glsdk_fn_clone_onchainreceiveresponse,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_free_onchainreceiveresponse,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_glsdk_fn_clone_onchainsendresponse,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_free_onchainsendresponse,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_glsdk_fn_clone_receiveresponse,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_free_receiveresponse,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_glsdk_fn_clone_scheduler,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_free_scheduler,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_glsdk_fn_constructor_scheduler_new,
[RustBuffer.by_value, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_method_scheduler_recover,
[:pointer, :pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_method_scheduler_register,
[:pointer, :pointer, RustBuffer.by_value, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_clone_sendresponse,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_free_sendresponse,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_glsdk_fn_clone_signer,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_free_signer,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_glsdk_fn_constructor_signer_new,
[RustBuffer.by_value, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_method_signer_authenticate,
[:pointer, :pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_glsdk_fn_method_signer_node_id,
[:pointer, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_glsdk_fn_method_signer_start,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :ffi_glsdk_rustbuffer_alloc,
[:uint64, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :ffi_glsdk_rustbuffer_from_bytes,
[ForeignBytes, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :ffi_glsdk_rustbuffer_free,
[RustBuffer.by_value, RustCallStatus.by_ref],
:void
attach_function :ffi_glsdk_rustbuffer_reserve,
[RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_glsdk_checksum_method_credentials_save,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_method_handle_stop,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_method_node_onchain_receive,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_method_node_onchain_send,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_method_node_receive,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_method_node_send,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_method_node_stop,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_method_scheduler_recover,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_method_scheduler_register,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_method_signer_authenticate,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_method_signer_node_id,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_method_signer_start,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_constructor_credentials_load,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_constructor_node_new,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_constructor_scheduler_new,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_glsdk_checksum_constructor_signer_new,
[RustCallStatus.by_ref],
:uint16
attach_function :ffi_glsdk_uniffi_contract_version,
[RustCallStatus.by_ref],
:uint32
end
class Network
BITCOIN = 1
REGTEST = 2
end
class PayStatus
COMPLETE = 1
PENDING = 2
FAILED = 3
end
class Credentials
def self.uniffi_allocate(pointer)
pointer.autorelease = false
inst = allocate
inst.instance_variable_set :@pointer, pointer
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_pointer(pointer, inst.object_id))
return inst
end
def self.uniffi_define_finalizer_by_pointer(pointer, object_id)
Proc.new do |_id|
Glsdk.rust_call(
:uniffi_glsdk_fn_free_credentials,
pointer
)
end
end
def self.uniffi_check_lower(inst)
if not inst.is_a? self
raise TypeError.new "Expected a Credentials instance, got #{inst}"
end
end
def uniffi_clone_pointer()
return Glsdk.rust_call(
:uniffi_glsdk_fn_clone_credentials,
@pointer
)
end
def self.uniffi_lower(inst)
return inst.uniffi_clone_pointer()
end
def self.load(raw)
raw = Glsdk::uniffi_bytes(raw)
return uniffi_allocate(Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_constructor_credentials_load,RustBuffer.allocFromBytes(raw)))
end
def save()
result = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_method_credentials_save,uniffi_clone_pointer(),)
return result.consumeIntoBytes
end
end
class Handle
def self.uniffi_allocate(pointer)
pointer.autorelease = false
inst = allocate
inst.instance_variable_set :@pointer, pointer
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_pointer(pointer, inst.object_id))
return inst
end
def self.uniffi_define_finalizer_by_pointer(pointer, object_id)
Proc.new do |_id|
Glsdk.rust_call(
:uniffi_glsdk_fn_free_handle,
pointer
)
end
end
def self.uniffi_check_lower(inst)
if not inst.is_a? self
raise TypeError.new "Expected a Handle instance, got #{inst}"
end
end
def uniffi_clone_pointer()
return Glsdk.rust_call(
:uniffi_glsdk_fn_clone_handle,
@pointer
)
end
def self.uniffi_lower(inst)
return inst.uniffi_clone_pointer()
end
def stop()
Glsdk.rust_call(:uniffi_glsdk_fn_method_handle_stop,uniffi_clone_pointer(),)
end
end
class Node
def self.uniffi_allocate(pointer)
pointer.autorelease = false
inst = allocate
inst.instance_variable_set :@pointer, pointer
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_pointer(pointer, inst.object_id))
return inst
end
def self.uniffi_define_finalizer_by_pointer(pointer, object_id)
Proc.new do |_id|
Glsdk.rust_call(
:uniffi_glsdk_fn_free_node,
pointer
)
end
end
def self.uniffi_check_lower(inst)
if not inst.is_a? self
raise TypeError.new "Expected a Node instance, got #{inst}"
end
end
def uniffi_clone_pointer()
return Glsdk.rust_call(
:uniffi_glsdk_fn_clone_node,
@pointer
)
end
def self.uniffi_lower(inst)
return inst.uniffi_clone_pointer()
end
def initialize(credentials)
credentials = credentials
(Credentials.uniffi_check_lower credentials)
pointer = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_constructor_node_new,(Credentials.uniffi_lower credentials))
@pointer = pointer
ObjectSpace.define_finalizer(self, self.class.uniffi_define_finalizer_by_pointer(pointer, self.object_id))
end
def onchain_receive()
result = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_method_node_onchain_receive,uniffi_clone_pointer(),)
return OnchainReceiveResponse.uniffi_allocate(result)
end
def onchain_send(destination, amount_or_all)
destination = Glsdk::uniffi_utf8(destination)
amount_or_all = Glsdk::uniffi_utf8(amount_or_all)
result = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_method_node_onchain_send,uniffi_clone_pointer(),RustBuffer.allocFromString(destination),RustBuffer.allocFromString(amount_or_all))
return OnchainSendResponse.uniffi_allocate(result)
end
def receive(label, description, amount_msat)
label = Glsdk::uniffi_utf8(label)
description = Glsdk::uniffi_utf8(description)
amount_msat = (amount_msat ? Glsdk::uniffi_in_range(amount_msat, "u64", 0, 2**64) : nil)
RustBuffer.check_lower_Optionalu64(amount_msat)
result = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_method_node_receive,uniffi_clone_pointer(),RustBuffer.allocFromString(label),RustBuffer.allocFromString(description),RustBuffer.alloc_from_Optionalu64(amount_msat))
return ReceiveResponse.uniffi_allocate(result)
end
def send(invoice, amount_msat)
invoice = Glsdk::uniffi_utf8(invoice)
amount_msat = (amount_msat ? Glsdk::uniffi_in_range(amount_msat, "u64", 0, 2**64) : nil)
RustBuffer.check_lower_Optionalu64(amount_msat)
result = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_method_node_send,uniffi_clone_pointer(),RustBuffer.allocFromString(invoice),RustBuffer.alloc_from_Optionalu64(amount_msat))
return SendResponse.uniffi_allocate(result)
end
def stop()
Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_method_node_stop,uniffi_clone_pointer(),)
end
end
class OnchainReceiveResponse
def self.uniffi_allocate(pointer)
pointer.autorelease = false
inst = allocate
inst.instance_variable_set :@pointer, pointer
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_pointer(pointer, inst.object_id))
return inst
end
def self.uniffi_define_finalizer_by_pointer(pointer, object_id)
Proc.new do |_id|
Glsdk.rust_call(
:uniffi_glsdk_fn_free_onchainreceiveresponse,
pointer
)
end
end
def self.uniffi_check_lower(inst)
if not inst.is_a? self
raise TypeError.new "Expected a OnchainReceiveResponse instance, got #{inst}"
end
end
def uniffi_clone_pointer()
return Glsdk.rust_call(
:uniffi_glsdk_fn_clone_onchainreceiveresponse,
@pointer
)
end
def self.uniffi_lower(inst)
return inst.uniffi_clone_pointer()
end
end
class OnchainSendResponse
def self.uniffi_allocate(pointer)
pointer.autorelease = false
inst = allocate
inst.instance_variable_set :@pointer, pointer
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_pointer(pointer, inst.object_id))
return inst
end
def self.uniffi_define_finalizer_by_pointer(pointer, object_id)
Proc.new do |_id|
Glsdk.rust_call(
:uniffi_glsdk_fn_free_onchainsendresponse,
pointer
)
end
end
def self.uniffi_check_lower(inst)
if not inst.is_a? self
raise TypeError.new "Expected a OnchainSendResponse instance, got #{inst}"
end
end
def uniffi_clone_pointer()
return Glsdk.rust_call(
:uniffi_glsdk_fn_clone_onchainsendresponse,
@pointer
)
end
def self.uniffi_lower(inst)
return inst.uniffi_clone_pointer()
end
end
class ReceiveResponse
def self.uniffi_allocate(pointer)
pointer.autorelease = false
inst = allocate
inst.instance_variable_set :@pointer, pointer
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_pointer(pointer, inst.object_id))
return inst
end
def self.uniffi_define_finalizer_by_pointer(pointer, object_id)
Proc.new do |_id|
Glsdk.rust_call(
:uniffi_glsdk_fn_free_receiveresponse,
pointer
)
end
end
def self.uniffi_check_lower(inst)
if not inst.is_a? self
raise TypeError.new "Expected a ReceiveResponse instance, got #{inst}"
end
end
def uniffi_clone_pointer()
return Glsdk.rust_call(
:uniffi_glsdk_fn_clone_receiveresponse,
@pointer
)
end
def self.uniffi_lower(inst)
return inst.uniffi_clone_pointer()
end
end
class Scheduler
def self.uniffi_allocate(pointer)
pointer.autorelease = false
inst = allocate
inst.instance_variable_set :@pointer, pointer
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_pointer(pointer, inst.object_id))
return inst
end
def self.uniffi_define_finalizer_by_pointer(pointer, object_id)
Proc.new do |_id|
Glsdk.rust_call(
:uniffi_glsdk_fn_free_scheduler,
pointer
)
end
end
def self.uniffi_check_lower(inst)
if not inst.is_a? self
raise TypeError.new "Expected a Scheduler instance, got #{inst}"
end
end
def uniffi_clone_pointer()
return Glsdk.rust_call(
:uniffi_glsdk_fn_clone_scheduler,
@pointer
)
end
def self.uniffi_lower(inst)
return inst.uniffi_clone_pointer()
end
def initialize(network)
network = network
RustBuffer.check_lower_TypeNetwork(network)
pointer = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_constructor_scheduler_new,RustBuffer.alloc_from_TypeNetwork(network))
@pointer = pointer
ObjectSpace.define_finalizer(self, self.class.uniffi_define_finalizer_by_pointer(pointer, self.object_id))
end
def recover(signer)
signer = signer
(Signer.uniffi_check_lower signer)
result = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_method_scheduler_recover,uniffi_clone_pointer(),(Signer.uniffi_lower signer))
return Credentials.uniffi_allocate(result)
end
def register(signer, code)
signer = signer
(Signer.uniffi_check_lower signer)
code = (code ? Glsdk::uniffi_utf8(code) : nil)
RustBuffer.check_lower_Optionalstring(code)
result = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_method_scheduler_register,uniffi_clone_pointer(),(Signer.uniffi_lower signer),RustBuffer.alloc_from_Optionalstring(code))
return Credentials.uniffi_allocate(result)
end
end
class SendResponse
def self.uniffi_allocate(pointer)
pointer.autorelease = false
inst = allocate
inst.instance_variable_set :@pointer, pointer
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_pointer(pointer, inst.object_id))
return inst
end
def self.uniffi_define_finalizer_by_pointer(pointer, object_id)
Proc.new do |_id|
Glsdk.rust_call(
:uniffi_glsdk_fn_free_sendresponse,
pointer
)
end
end
def self.uniffi_check_lower(inst)
if not inst.is_a? self
raise TypeError.new "Expected a SendResponse instance, got #{inst}"
end
end
def uniffi_clone_pointer()
return Glsdk.rust_call(
:uniffi_glsdk_fn_clone_sendresponse,
@pointer
)
end
def self.uniffi_lower(inst)
return inst.uniffi_clone_pointer()
end
end
class Signer
def self.uniffi_allocate(pointer)
pointer.autorelease = false
inst = allocate
inst.instance_variable_set :@pointer, pointer
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_pointer(pointer, inst.object_id))
return inst
end
def self.uniffi_define_finalizer_by_pointer(pointer, object_id)
Proc.new do |_id|
Glsdk.rust_call(
:uniffi_glsdk_fn_free_signer,
pointer
)
end
end
def self.uniffi_check_lower(inst)
if not inst.is_a? self
raise TypeError.new "Expected a Signer instance, got #{inst}"
end
end
def uniffi_clone_pointer()
return Glsdk.rust_call(
:uniffi_glsdk_fn_clone_signer,
@pointer
)
end
def self.uniffi_lower(inst)
return inst.uniffi_clone_pointer()
end
def initialize(phrase)
phrase = Glsdk::uniffi_utf8(phrase)
pointer = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_constructor_signer_new,RustBuffer.allocFromString(phrase))
@pointer = pointer
ObjectSpace.define_finalizer(self, self.class.uniffi_define_finalizer_by_pointer(pointer, self.object_id))
end
def authenticate(creds)
creds = creds
(Credentials.uniffi_check_lower creds)
result = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_method_signer_authenticate,uniffi_clone_pointer(),(Credentials.uniffi_lower creds))
return Signer.uniffi_allocate(result)
end
def node_id()
result = Glsdk.rust_call(:uniffi_glsdk_fn_method_signer_node_id,uniffi_clone_pointer(),)
return result.consumeIntoBytes
end
def start()
result = Glsdk.rust_call_with_error(Error,:uniffi_glsdk_fn_method_signer_start,uniffi_clone_pointer(),)
return Handle.uniffi_allocate(result)
end
end
end