Skip to content

Commit

Permalink
Finish implementing LedgerEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
lucca65 committed Mar 4, 2024
1 parent 232b444 commit e3951dd
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 2 deletions.
73 changes: 71 additions & 2 deletions lib/ledger_entry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,75 @@ defmodule XRPL.LedgerEntry do
})
end

# def ledger_entry(:ripple_state, ledger_index, accounts, currency) do
# end
def ripple_state(ledger_index, accounts, currency) do
post("/", %{
method: "ledger_entry",
params: [
%{ripple_state: %{accounts: accounts, currency: currency}, ledger_index: ledger_index}
]
})
end

def check(ledger_index, object_id) do
post("/", %{
method: "ledger_entry",
params: [%{check: object_id, ledger_index: ledger_index}]
})
end

def escrow(ledger_index, object_id) do
post("/", %{
method: "ledger_entry",
params: [%{escrow: object_id, ledger_index: ledger_index}]
})
end

def escrow(ledger_index, owner, seq) do
post("/", %{
method: "ledger_entry",
params: [%{escrow: %{owner: owner, seq: seq}, ledger_index: ledger_index}]
})
end

def payment_channel(ledger_index, object_id) do
post("/", %{
method: "ledger_entry",
params: [%{payment_channel: object_id, ledger_index: ledger_index}]
})
end

def deposit_preauth(ledger_index, object_id) do
post("/", %{
method: "ledger_entry",
params: [%{deposit_preauth: object_id, ledger_index: ledger_index}]
})
end

def deposit_preauth(ledger_index, owner, authorized) do
post("/", %{
method: "ledger_entry",
params: [%{deposit_preauth: %{owner: owner, authorized: authorized}, ledger_index: ledger_index}]
})
end

def ticket(ledger_index, ledger_entry_id) do
post("/", %{
method: "ledger_entry",
params: [%{ticket: ledger_entry_id, ledger_index: ledger_index}]
})
end

def ticket(ledger_index, account, seq) do
post("/", %{
method: "ledger_entry",
params: [%{ticket: %{account: account, ticket_seq: seq}, ledger_index: ledger_index}]
})
end

def nft_page(ledger_index, ledger_entry_id) do
post("/", %{
method: "ledger_entry",
params: [%{nft_page: ledger_entry_id, ledger_index: ledger_index}]
})
end
end
125 changes: 125 additions & 0 deletions test/ledger_entry_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,129 @@ defmodule XRPLTest.LedgerEntryTest do
assert env.status == 200
end
end

describe "ripple_state/3" do
test "returns ripple state by sending ripple state object" do
assert(
{:ok, %Tesla.Env{} = env} =
LedgerEntry.ripple_state(
"validated",
[
"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW"
],
"USD"
)
)

assert env.status == 200
end
end

describe "check/2" do
test "returns check by sending check object" do
assert(
{:ok, %Tesla.Env{} = env} =
LedgerEntry.check("validated", "C4A46CCD8F096E994C4B0DEAB6CE98E722FC17D7944C28B95127C2659C47CBEB")
)

assert env.status == 200
end
end

describe "escrow/2 and escrow/3" do
test "escrow/2" do
assert(
{:ok, %Tesla.Env{} = env} =
LedgerEntry.escrow(
"validated",
"917ACF1324F06D19239A03E4A6A3FE24F9313BB23337ECB801BDAD013BE27F83"
)
)

assert env.status == 200
end

test "escrow/3" do
assert(
{:ok, %Tesla.Env{} = env} =
LedgerEntry.escrow(
"validated",
"rL4fPHi2FWGwRGRQSH7gBcxkuo2b9NTjKK",
126
)
)

assert env.status == 200
end
end

describe "payment_channel/2" do
test "returns payment channel by sending payment channel object" do
assert(
{:ok, %Tesla.Env{} = env} =
LedgerEntry.payment_channel(
"validated",
"C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7"
)
)

assert env.status == 200
end
end

describe "deposit_preauth/2 and deposit_preauth/3" do
test "deposit_preauth/2" do
assert(
{:ok, %Tesla.Env{} = env} =
LedgerEntry.deposit_preauth(
"validated",
"A43898B685C450DE8E194B24D9D54E62530536A770CCB311BFEE15A27381ABB2"
)
)

assert env.status == 200
end

test "deposit_preauth/3" do
assert(
{:ok, %Tesla.Env{} = env} =
LedgerEntry.deposit_preauth(
"validated",
"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"ra5nK24KXen9AHvsdFTKHSANinZseWnPcX"
)
)

assert env.status == 200
end
end

describe "ticket/2 and ticket/3" do
test "ticket/2" do
assert(
{:ok, %Tesla.Env{} = env} =
LedgerEntry.ticket("validated", "B603682BC36F474F708E1A150B7C034C6C13D838C3F2F135CDB7BEA6E5B5ACEF")
)

assert env.status == 200
end

test "ticket/3" do
assert({:ok, %Tesla.Env{} = env} = LedgerEntry.ticket("validated", "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", 389))

assert env.status == 200
end
end

describe "nft_page/2" do
test "returns nft by sending ledger entry ID" do
assert(
{:ok, %Tesla.Env{} = env} =
LedgerEntry.nft_page("validated", "255DD86DDF59D778081A06D02701E9B2C9F4F01DFFFFFFFFFFFFFFFFFFFFFFFF")
)

assert env.status == 200
end
end
end

0 comments on commit e3951dd

Please sign in to comment.