Skip to content

Commit

Permalink
server: remove useless calls to getAddressBalance and getTransactions…
Browse files Browse the repository at this point in the history
…, issue #48
  • Loading branch information
Jonathan committed Jul 19, 2019
1 parent 163b165 commit 37c8b75
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 153 deletions.
60 changes: 0 additions & 60 deletions server/app/com/xsn/explorer/services/XSNService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ trait XSNService {

def getRawTransaction(txid: TransactionId): FutureApplicationResult[JsValue]

def getAddressBalance(address: Address): FutureApplicationResult[rpc.AddressBalance]

def getTransactions(address: Address): FutureApplicationResult[List[TransactionId]]

def getBlock(blockhash: Blockhash): FutureApplicationResult[rpc.Block.Canonical]

def getFullBlock(blockhash: Blockhash): FutureApplicationResult[rpc.Block.HasTransactions[rpc.TransactionVIN]]
Expand Down Expand Up @@ -110,62 +106,6 @@ class XSNServiceRPCImpl @Inject()(ws: WSClient, rpcConfig: RPCConfig, explorerCo
}
}

override def getAddressBalance(address: Address): FutureApplicationResult[rpc.AddressBalance] = {
val body = s"""
|{
| "jsonrpc": "1.0",
| "method": "getaddressbalance",
| "params": [
| { "addresses": ["${address.string}"] }
| ]
|}
|""".stripMargin

// the network returns 0 for valid addresses
val errorCodeMapper = Map(-5 -> AddressFormatError)

server
.post(body)
.map { response =>
val maybe = getResult[rpc.AddressBalance](response, errorCodeMapper)
maybe.getOrElse {
logger.warn(
s"Unexpected response from XSN Server, status = ${response.status}, address = ${address.string}, response = ${response.body}"
)

Bad(XSNUnexpectedResponseError).accumulating
}
}
}

override def getTransactions(address: Address): FutureApplicationResult[List[TransactionId]] = {
val body = s"""
|{
| "jsonrpc": "1.0",
| "method": "getaddresstxids",
| "params": [
| { "addresses": ["${address.string}"] }
| ]
|}
|""".stripMargin

// the network returns 0 for valid addresses
val errorCodeMapper = Map(-5 -> AddressFormatError)

server
.post(body)
.map { response =>
val maybe = getResult[List[TransactionId]](response, errorCodeMapper)
maybe.getOrElse {
logger.warn(
s"Unexpected response from XSN Server, status = ${response.status}, address = ${address.string}, response = ${response.body}"
)

Bad(XSNUnexpectedResponseError).accumulating
}
}
}

override def getBlock(blockhash: Blockhash): FutureApplicationResult[rpc.Block.Canonical] = {
val errorCodeMapper = Map(-5 -> BlockNotFoundError)
val body = s"""{ "jsonrpc": "1.0", "method": "getblock", "params": ["${blockhash.string}"] }"""
Expand Down
2 changes: 0 additions & 2 deletions server/test/com/xsn/explorer/helpers/DummyXSNService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class DummyXSNService extends XSNService {
Blockhash.from("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34").get
override def getTransaction(txid: TransactionId): FutureApplicationResult[Transaction[TransactionVIN]] = ???
override def getRawTransaction(txid: TransactionId): FutureApplicationResult[JsValue] = ???
override def getAddressBalance(address: Address): FutureApplicationResult[rpc.AddressBalance] = ???
override def getTransactions(address: Address): FutureApplicationResult[List[TransactionId]] = ???
override def getBlock(blockhash: Blockhash): FutureApplicationResult[rpc.Block.Canonical] = ???
override def getFullBlock(blockhash: Blockhash): FutureApplicationResult[Block.HasTransactions[TransactionVIN]] = ???
override def getRawBlock(blockhash: Blockhash): FutureApplicationResult[JsValue] = ???
Expand Down
91 changes: 0 additions & 91 deletions server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,97 +214,6 @@ class XSNServiceRPCImplSpec extends WordSpec {
}
}

"getAddressBalance" should {
"return the balance" in {
val responseBody =
"""
|{
| "result": {
| "balance": 2465010000000000,
| "received": 1060950100000000
| },
| "error": null,
| "id": null
|}
""".stripMargin.trim

val address = Address.from("Xi3sQfMQsy2CzMZTrnKW6HFGp1VqFThdLw").get

val json = Json.parse(responseBody)

mockRequest(request, response)(200, json)

whenReady(service.getAddressBalance(address)) { result =>
result.isGood mustEqual true

val balance = result.get
balance.balance mustEqual BigDecimal("24650100.00000000")
balance.received mustEqual BigDecimal("10609501.00000000")
}
}

"fail on invalid address" in {
val responseBody = createRPCErrorResponse(-5, "Invalid address")
val address = Address.from("Xi3sQfMQsy2CzMZTrnKW6HFGp1VqFThdLW").get

val json = Json.parse(responseBody)

mockRequest(request, response)(200, json)

whenReady(service.getAddressBalance(address)) { result =>
result mustEqual Bad(AddressFormatError).accumulating
}
}
}

"getTransactions" should {
"return the transactions" in {
val responseBody =
"""
|{
| "result": [
| "3963203e8ff99c0effbc7c90ef1b534f7e60d9d4d1d131375bc73eb6af8b62d0",
| "56eff1fc3ec29277a039944a10826e1bd24685bec5e5c46c946846cb859dc14b",
| "d5718b83b6cec30e075c20dc61005a25a6eb707f14b92e89c2a9c4bc39635b5d",
| "9cd1d22e786b7b8722ce51f551c3c5af2053a52bd7694b9ef79e0a5d95053b19",
| "1dbf0277891ed39f8175fa08844eadbb6ed4b28464fbac0ba88464001192d79e",
| "2520ec229a76db8efa8e3b384582ac5c1969224a97f32475b957151f0c8cdfa7",
| "46d2f51afeab7aeb7adab821c374c7348ae0ff4edb7d0c9af995360630194cc8",
| "1a91406280e2a77dc0baf8a13491a977cba2d2dae6a8ba93fc6bbd3a7aeec4e5",
| "def0ae8bbfa45dca177f9c9f169e362bd25dee460a8ddc8c662e92e6968cd6d8"
| ],
| "error": null,
| "id": null
|}
""".stripMargin.trim

val address = Address.from("Xi3sQfMQsy2CzMZTrnKW6HFGp1VqFThdLw").get

val json = Json.parse(responseBody)

mockRequest(request, response)(200, json)

whenReady(service.getTransactions(address)) { result =>
result.isGood mustEqual true
result.get.size mustEqual 9
}
}

"fail on invalid address" in {
val responseBody = """{"result":null,"error":{"code":-5,"message":"Invalid address"},"id":null}"""

val address = Address.from("Xi3sQfMQsy2CzMZTrnKW6HFGp1VqFThdLW").get

val json = Json.parse(responseBody)

mockRequest(request, response)(200, json)

whenReady(service.getTransactions(address)) { result =>
result mustEqual Bad(AddressFormatError).accumulating
}
}
}

"getBlock" should {
"return the genesis block" in {
val block = BlockLoader.json("00000c822abdbb23e28f79a49d29b41429737c6c7e15df40d1b1f1b35907ae34")
Expand Down

0 comments on commit 37c8b75

Please sign in to comment.