Skip to content

Instantly share code, notes, and snippets.

@MattKetmo
Last active July 8, 2022 07:27
Show Gist options
  • Select an option

  • Save MattKetmo/d542d3d25745c0b6e1f27fc5401cfe9f to your computer and use it in GitHub Desktop.

Select an option

Save MattKetmo/d542d3d25745c0b6e1f27fc5401cfe9f to your computer and use it in GitHub Desktop.

Revisions

  1. MattKetmo revised this gist Jul 8, 2022. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ func main() {

    result := searchBlock(address, fromBlock, toBlock)
    if result < fromBlock || result > toBlock {
    fmt.Printf("error: result must be between %d and %d (actual: %d)", fromBlock, toBlock, result)
    fmt.Printf("error: result must be between %d and %d (actual: %d)\n", fromBlock, toBlock, result)
    os.Exit(1)
    }

    @@ -22,13 +22,13 @@ func main() {
    // Find the block where the balance of the given address changed.
    func searchBlock(address string, fromBlock, toBlock int) int {
    // TODO
    return toBlock
    return 0
    }

    // Return the balance of an address at a given block.
    //
    // Example with curl:
    // curl -XPOST -H "Content-Type: application/json" https://goerli.infura.io/v3/xxxxxxxxxxxxxxxx \
    // curl -XPOST -H "Content-Type: application/json" https://goerli.infura.io/v3/1958344898c54b909598f1d0b8457805 \
    // -d '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xbad1568bf8d55f5f808edec0cd7394ebd8d51d0e", "0x6a6ec1"],"id":1}'
    func getBalance(address string, blockId int) string {
    // TODO
  2. MattKetmo created this gist Jul 8, 2022.
    36 changes: 36 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    package main

    import (
    "fmt"
    "os"
    )

    func main() {
    address := "0xbad1568bf8d55f5f808edec0cd7394ebd8d51d0e"
    fromBlock := 6974800
    toBlock := 6974900

    result := searchBlock(address, fromBlock, toBlock)
    if result < fromBlock || result > toBlock {
    fmt.Printf("error: result must be between %d and %d (actual: %d)", fromBlock, toBlock, result)
    os.Exit(1)
    }

    fmt.Printf("result = %d\n", result)
    }

    // Find the block where the balance of the given address changed.
    func searchBlock(address string, fromBlock, toBlock int) int {
    // TODO
    return toBlock
    }

    // Return the balance of an address at a given block.
    //
    // Example with curl:
    // curl -XPOST -H "Content-Type: application/json" https://goerli.infura.io/v3/xxxxxxxxxxxxxxxx \
    // -d '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xbad1568bf8d55f5f808edec0cd7394ebd8d51d0e", "0x6a6ec1"],"id":1}'
    func getBalance(address string, blockId int) string {
    // TODO
    return "0"
    }