Skip to content

Commit

Permalink
Merge branch 'ethereum' of github.com:tokenanalyst/blockchain-rpc int…
Browse files Browse the repository at this point in the history
…o more_rename

# Conflicts:
#	src/main/scala/examples/bitcoin/CatchupFromZero.scala
#	src/main/scala/examples/bitcoin/GetAllTransactionsForBlock.scala
#	src/main/scala/examples/bitcoin/GetBlockHash.scala
#	src/main/scala/examples/bitcoin/SubscribeToBlockUpdates.scala
  • Loading branch information
CesarPantoja committed Dec 17, 2019
1 parent e1ec41b commit 93db21f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ object CatchupFromZero extends IOApp {
| getBlockByHeight(long: Height) | Get a block by height | |
| getBlockByHash(hash: String) |Get a block by hash | |
| getBestBlockHeight | Get the best block height | |
| getTransaction(hash: String) |Get a transaction by hash| |
| getBlockWithTransactionsByHeight | Get a block with transactions by height | |
| getBlockWithTransactionsByHash |Get a block with transactions by hash | |
| getTransaction(hash: String) |Get a transaction by hash| eth_getTransactionByHash |
| getTransactions(hashes: Seq[String]) |Get a batch of transaction by hash| eth_getTransactionByHash |
| getReceiptByHash(hash: String) | Get a transaction receipt by hash | |
| getReceiptsByHash(hashes: Seq[String]) |Get transaction receipts by hashes | |

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/ethereum/Protocol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object Protocol {
s: String,
v: String,
standardV: String,
to: String,
to: Option[String],
transactionIndex: String,
value: String,
condition: Option[String],
Expand Down
12 changes: 4 additions & 8 deletions src/main/scala/ethereum/Syntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ object Syntax {
def getNextBlockHash() =
implicitly[GetNextBlockHash[Ethereum]].getNextBlockHash(b)

def getBlockWithTransactionsByHeight(height: Long) =
implicitly[GetBlockByHeight[Ethereum, BlockWithTransactionsResponse]]
.getBlockByHeight(b, height)

def getBlockWithTransactionsByHash(hash: String) =
implicitly[GetBlockByHash[Ethereum, BlockWithTransactionsResponse]]
.getBlockByHash(b, hash)

def getReceiptByHash(hash: String) =
implicitly[GetReceipt[Ethereum, ReceiptResponse]].getReceipt(b, hash)

Expand All @@ -57,5 +49,9 @@ object Syntax {
def getTransaction(hash: String) =
implicitly[GetTransaction[Ethereum, TransactionResponse]]
.getTransaction(b, hash)

def getTransactions(hashes: Seq[String]) =
implicitly[GetTransactions[Ethereum, BatchResponse[TransactionResponse]]]
.getTransactions(b, hashes)
}
}
11 changes: 7 additions & 4 deletions src/main/scala/examples/ethereum/CatchupFromZero.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ package io.tokenanalyst.blockchainrpc.examples.ethereum
import cats.effect.{ExitCode, IO, IOApp}
import io.tokenanalyst.blockchainrpc.ethereum.Syntax._
import io.tokenanalyst.blockchainrpc.ethereum.HexTools
import io.tokenanalyst.blockchainrpc.{Config, Ethereum, RPCClient}
import io.tokenanalyst.blockchainrpc.ethereum.Protocol.TransactionResponse
import io.tokenanalyst.blockchainrpc.{BatchResponse, Config, Ethereum, RPCClient}

import scala.concurrent.ExecutionContext.global

Expand All @@ -31,11 +32,13 @@ object CatchupFromZero extends IOApp {
_ <- IO(println(s"${receipts.seq.size} receipts"))
} yield ()

def loop(rpc: Ethereum, current: Long = 0L, until: Long = 1000000L): IO[Unit] =
def loop(rpc: Ethereum, current: Long = 9000000L, until: Long = 9120000): IO[Unit] =
for {
block <- rpc.getBlockWithTransactionsByHeight(current)
block <- rpc.getBlockByHeight(current)
_ <- IO { println(s"block ${HexTools.parseQuantity(block.number)} - ${block.hash}: ${block.transactions.size} transactions") }
_ <- if(block.transactions.nonEmpty) getReceipts(rpc, block.transactions.map(_.hash)) else IO.unit
transactions <- if(block.transactions.nonEmpty) rpc.getTransactions(block.transactions) else IO.pure(BatchResponse[TransactionResponse](List()))
_ <- IO(println(s"transactions: ${transactions.seq.size}"))
_ <- if(block.transactions.nonEmpty) getReceipts(rpc, block.transactions) else IO.unit
l <- if (current + 1 < until) loop(rpc, current + 1, until) else IO.unit
} yield l

Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/ethereum/ProtocolSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class ProtocolSpec extends AnyFlatSpec with Matchers with DiffMatcher {
"0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c",
"0x25",
"0x0",
"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb",
Some("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb"),
"0x41",
"0xf3dbb76162000",
None,
Expand Down

0 comments on commit 93db21f

Please sign in to comment.