Skip to content

Commit

Permalink
Merge pull request #1127 from wavesplatform/NODE-771-Provide-sponsors…
Browse files Browse the repository at this point in the history
…hip-info-to-balance

NODE-771
  • Loading branch information
alexeykiselev authored May 25, 2018
2 parents 6272814 + 1f5ce9e commit e200499
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
7 changes: 6 additions & 1 deletion it/src/main/scala/com/wavesplatform/it/api/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ object CompiledScript {
implicit val compiledScriptFormat: Format[CompiledScript] = Json.format
}

case class FullAssetInfo(assetId: String, balance: Long, reissuable: Boolean, quantity: Long)
case class FullAssetInfo(assetId: String,
balance: Long,
reissuable: Boolean,
minSponsoredAssetFee: Option[Long],
sponsorBalance: Option[Long],
quantity: Long)
object FullAssetInfo {
implicit val fullAssetInfoFormat: Format[FullAssetInfo] = Json.format
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class SponsorshipSuite extends FreeSpec with NodesFromDocker with Matchers with
miner.assertBalances(sponsor.address, sponsorWavesBalance - 2.waves - minWavesFee)
miner.assertAssetBalance(alice.address, sponsorAssetId, sponsorAssetTotal / 2)

val assetInfo = alice.assetsBalance(alice.address).balances.filter(_.assetId == sponsorAssetId).head
assetInfo.minSponsoredAssetFee shouldBe Some(Token)
assetInfo.sponsorBalance shouldBe Some(sponsor.accountBalances(sponsor.address)._2)
}

"invalid tx if fee less then minimal" in {
Expand Down Expand Up @@ -120,6 +123,11 @@ class SponsorshipSuite extends FreeSpec with NodesFromDocker with Matchers with
"cancel sponsorship, cannot pay fees in non sponsored assets " in {
val cancelSponsorshipTxId = sponsor.cancelSponsorship(sponsor.address, sponsorAssetId, fee = 1.waves).id
nodes.waitForHeightAriseAndTxPresent(cancelSponsorshipTxId)

val assetInfo = alice.assetsBalance(alice.address).balances.filter(_.assetId == sponsorAssetId).head
assetInfo.minSponsoredAssetFee shouldBe None
assetInfo.sponsorBalance shouldBe None

assert(!cancelSponsorshipTxId.isEmpty)
assertSponsorship(sponsorAssetId, 0L)
assertBadRequestAndResponse(
Expand Down
22 changes: 16 additions & 6 deletions src/main/scala/scorex/api/http/assets/AssetsApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,25 @@ case class AssetsApiRoute(settings: RestAPISettings, wallet: Wallet, utx: UtxPoo
(for {
(assetId, balance) <- blockchain.portfolio(acc).assets
if balance > 0
assetInfo <- blockchain.assetDescription(assetId)
issueTransaction <- blockchain.transactionInfo(assetId)
assetInfo <- blockchain.assetDescription(assetId)
(_, (issueTransaction: IssueTransaction)) <- blockchain.transactionInfo(assetId)
sponsorBalance = if (assetInfo.sponsorship != 0) {
Some(blockchain.portfolio(issueTransaction.sender).balance)
} else {
None
}
} yield
Json.obj(
"assetId" -> assetId.base58,
"balance" -> balance,
"reissuable" -> assetInfo.reissuable,
"assetId" -> assetId.base58,
"balance" -> balance,
"reissuable" -> assetInfo.reissuable,
"minSponsoredAssetFee" -> (assetInfo.sponsorship match {
case 0 => JsNull
case sponsorship => JsNumber(sponsorship)
}),
"sponsorBalance" -> sponsorBalance,
"quantity" -> JsNumber(BigDecimal(assetInfo.totalVolume)),
"issueTransaction" -> issueTransaction._2.json()
"issueTransaction" -> issueTransaction.json()
)).toSeq)
)
}).left.map(ApiError.fromValidationError)
Expand Down

0 comments on commit e200499

Please sign in to comment.