Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Add ClaimableBalanceKey (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
Synesso committed Sep 20, 2020
1 parent 6c4e513 commit 3588573
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/main/scala/stellar/sdk/model/ledger/LedgerKey.scala
@@ -1,6 +1,7 @@
package stellar.sdk.model.ledger

import cats.data.State
import okio.ByteString
import stellar.sdk.model.xdr.{Decode, Encodable, Encode}
import stellar.sdk.model.{Asset, NonNativeAsset}
import stellar.sdk.{KeyPair, PublicKeyOps}
Expand All @@ -13,7 +14,8 @@ object LedgerKey extends Decode {
widen(AccountKey.decode),
widen(TrustLineKey.decode),
widen(OfferKey.decode),
widen(DataKey.decode)
widen(DataKey.decode),
widen(ClaimableBalanceKey.decode)
)
}

Expand Down Expand Up @@ -57,3 +59,13 @@ object DataKey extends Decode {
name <- string
} yield DataKey(account, name)
}

case class ClaimableBalanceKey(id: ByteString) extends LedgerKey {
override def encode: LazyList[Byte] = Encode.int(4) ++ Encode.bytes(32, id.toByteArray)
}

object ClaimableBalanceKey extends Decode {
val decode: State[Seq[Byte], ClaimableBalanceKey] = for {
id <- bytes(32).map(_.toArray).map(new ByteString(_))
} yield ClaimableBalanceKey(id)
}
Expand Up @@ -38,9 +38,13 @@ trait LedgerEntryGenerators extends ArbitraryInput {
name <- Gen.identifier
} yield DataKey(account, name)

val genLedgerKey: Gen[LedgerKey] = Gen.oneOf(genAccountKey, genTrustLineKey, genOfferKey, genDataKey)
val genClaimableBalanceKey: Gen[ClaimableBalanceKey] = for {
id <- Gen.containerOfN[Array, Byte](32, Gen.posNum[Byte]).map(new ByteString(_))
} yield ClaimableBalanceKey(id)

val genLedgerKey: Gen[LedgerKey] = Gen.oneOf(genAccountKey, genTrustLineKey, genOfferKey, genDataKey, genClaimableBalanceKey)

implicit val arbLedgerKey = Arbitrary(genLedgerKey)
implicit val arbLedgerKey: Arbitrary[LedgerKey] = Arbitrary(genLedgerKey)


// LedgerEntries
Expand Down

0 comments on commit 3588573

Please sign in to comment.