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

Commit

Permalink
Add support for signer sponsorship events
Browse files Browse the repository at this point in the history
  • Loading branch information
Synesso committed Feb 14, 2021
1 parent b952a75 commit 584a294
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps.

## Next version

## 0.19.1

- [#389](https://github.com/Synesso/scala-stellar-sdk/issues/389) Adds support for Signer Sponsorship state snapshot events.

## 0.19.0

- A wide-ranging review of the SDK resulted in realignments to SDK/Network interactions and some data types. This has
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Add the JitPack & jcenter resolvers and the [latest dependency](https://jitpack.
```scala
resolvers += "jitpack" at "https://jitpack.io"
resolvers += Resolver.jcenterRepo
libraryDependencies += "com.github.synesso" %% "scala-stellar-sdk" % "0.19.0"
libraryDependencies += "com.github.synesso" %% "scala-stellar-sdk" % "0.19.1"
```

From there, it is a simple affair to create and fund a new account on the test network.
Expand Down
19 changes: 19 additions & 0 deletions src/main/scala/stellar/sdk/model/response/EffectResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ case class EffectSignerUpdated(id: String, createdAt: ZonedDateTime, account: Pu

case class EffectSignerRemoved(id: String, createdAt: ZonedDateTime, account: PublicKeyOps, publicKey: String) extends EffectResponse

case class EffectSignerSponsorshipCreated(id: String, createdAt: ZonedDateTime, account: PublicKeyOps, signer: PublicKeyOps, newSponsor: PublicKeyOps) extends EffectResponse

case class EffectSignerSponsorshipRemoved(id: String, createdAt: ZonedDateTime, account: PublicKeyOps, signer: PublicKeyOps, formerSponsor: PublicKeyOps) extends EffectResponse

case class EffectSignerSponsorshipUpdated(id: String, createdAt: ZonedDateTime, account: PublicKeyOps, signer: PublicKeyOps, formerSponsor: PublicKeyOps, newSponsor: PublicKeyOps) extends EffectResponse

case class EffectTrustLineCreated(id: String, createdAt: ZonedDateTime, account: PublicKeyOps, limit: IssuedAmount) extends EffectResponse {
val asset: NonNativeAsset = limit.asset
}
Expand Down Expand Up @@ -120,6 +126,19 @@ object EffectResponseDeserializer extends ResponseParser[EffectResponse]({ o: JO
case "signer_created" => EffectSignerCreated(id, createdAt, account(), weight, (o \ "public_key").extract[String])
case "signer_updated" => EffectSignerUpdated(id, createdAt, account(), weight, (o \ "public_key").extract[String])
case "signer_removed" => EffectSignerRemoved(id, createdAt, account(), (o \ "public_key").extract[String])
case "signer_sponsorship_created" => EffectSignerSponsorshipCreated(id, createdAt, account(),
signer = account("signer"),
newSponsor = account("sponsor")
)
case "signer_sponsorship_removed" => EffectSignerSponsorshipRemoved(id, createdAt, account(),
signer = account("signer"),
formerSponsor = account("former_sponsor")
)
case "signer_sponsorship_updated" => EffectSignerSponsorshipUpdated(id, createdAt, account(),
signer = account("signer"),
formerSponsor = account("former_sponsor"),
newSponsor = account("new_sponsor")
)
case "trustline_created" => EffectTrustLineCreated(id, createdAt, account(), amount(key = "limit").asInstanceOf[IssuedAmount])
case "trustline_updated" => EffectTrustLineUpdated(id, createdAt, account(), amount(key = "limit").asInstanceOf[IssuedAmount])
case "trustline_removed" => EffectTrustLineRemoved(id, createdAt, account(), asset().asInstanceOf[NonNativeAsset])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ class SignerEffectResponseSpec extends Specification with ArbitraryInput with Js
}.setGen1(Gen.identifier).setGen4(Gen.identifier)
}

"a signer sponsorship created effect document" should {
"parse to a signer sponsorship created effect" >> prop { (id: String, created: ZonedDateTime, kp: KeyPair, signer: KeyPair, sponsor: KeyPair) =>
val json = doc(id, created, kp, "signer_sponsorship_created", 0, "signer" -> signer.accountId, "sponsor" -> sponsor.accountId)
parse(json).extract[EffectResponse] mustEqual EffectSignerSponsorshipCreated(id, created, kp.asPublicKey, signer.asPublicKey, sponsor.asPublicKey)
}.setGen1(Gen.identifier)
}

"a signer sponsorship removed effect document" should {
"parse to a signer sponsorship removed effect" >> prop { (id: String, created: ZonedDateTime, kp: KeyPair, signer: KeyPair, sponsor: KeyPair) =>
val json = doc(id, created, kp, "signer_sponsorship_removed", 0, "signer" -> signer.accountId, "former_sponsor" -> sponsor.accountId)
parse(json).extract[EffectResponse] mustEqual EffectSignerSponsorshipRemoved(id, created, kp.asPublicKey, signer.asPublicKey, sponsor.asPublicKey)
}.setGen1(Gen.identifier)
}

"a signer sponsorship updated effect document" should {
"parse to a signer sponsorship updated effect" >> prop { (id: String, created: ZonedDateTime, kp: KeyPair, signer: KeyPair, oldSponsor: KeyPair, newSponsor: KeyPair) =>
val json = doc(id, created, kp, "signer_sponsorship_updated", 0, "signer" -> signer.accountId, "former_sponsor" -> oldSponsor.accountId, "new_sponsor" -> newSponsor.accountId)
parse(json).extract[EffectResponse] mustEqual EffectSignerSponsorshipUpdated(id, created, kp.asPublicKey, signer.asPublicKey, oldSponsor.asPublicKey, newSponsor.asPublicKey)
}.setGen1(Gen.identifier)
}

def doc(id: String, created: ZonedDateTime, kp: KeyPair, tpe: String, weight: Short, extra: (String, Any)*) =
s"""
|{
Expand Down

0 comments on commit 584a294

Please sign in to comment.