~dcrck/solana

6233125b8159c8e09a458a26e02e9e61f478bf7e — dcrck 4 months ago 5925668
support Borsh string serialization
1 files changed, 6 insertions(+), 0 deletions(-)

M lib/solana/ix.ex
M lib/solana/ix.ex => lib/solana/ix.ex +6 -0
@@ 30,6 30,12 @@ defmodule Solana.Instruction do
    <<byte_size(value)::little-size(32), 0::32, value::binary>>
  end

  # encodes a string in Borsh's expected format
  # https://borsh.io/#pills-specification
  defp encode_value({value, "borsh"}) when is_binary(value) do
    <<byte_size(value)::little-size(32), value::binary>>
  end

  defp encode_value({value, size}), do: encode_value({value, size, :little})
  defp encode_value({value, size, :big}), do: <<value::size(size)-big>>
  defp encode_value({value, size, :little}), do: <<value::size(size)-little>>