Skip to content

Instantly share code, notes, and snippets.

@cpacia
Last active November 29, 2019 10:51
Show Gist options
  • Save cpacia/97fbcb4816a506b27d1a4219cadd1a92 to your computer and use it in GitHub Desktop.
Save cpacia/97fbcb4816a506b27d1a4219cadd1a92 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/binary"
"fmt"
"github.com/gcash/bchd/bchrpc/pb"
"github.com/gcash/bchd/txscript"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"log"
"path/filepath"
"time"
"github.com/gcash/bchutil"
)
func main() {
certificateFile := filepath.Join(bchutil.AppDataDir("bchd", false), "rpc.cert")
creds, err := credentials.NewClientTLSFromFile(certificateFile, "localhost")
if err != nil {
log.Fatal(err)
}
conn, err := grpc.Dial("localhost:8335", grpc.WithTransportCredentials(creds))
if err != nil {
log.Fatal(err)
}
defer conn.Close()
var (
client = pb.NewBchrpcClient(conn)
beginingTimestamp = int64(1230940800)
endingTimestamp = int64(1282435200)
height = int32(0)
found []string
start = time.Now()
)
for {
resp, err := client.GetBlock(context.Background(), &pb.GetBlockRequest{
HashOrHeight: &pb.GetBlockRequest_Height{Height: height},
FullTransactions: true,
})
if err != nil {
log.Fatal(err)
}
height++
nonce := make([]byte, 4)
binary.LittleEndian.PutUint32(nonce, resp.Block.Info.Nonce)
if nonce[0] > 58 {
continue
}
if resp.Block.Info.Timestamp < beginingTimestamp {
continue
}
if resp.Block.Info.Timestamp > endingTimestamp {
break
}
if len(resp.Block.TransactionData[0].GetTransaction().Outputs) != 1 {
continue
}
if resp.Block.TransactionData[0].GetTransaction().Outputs[0].ScriptClass != txscript.PubKeyTy.String() {
continue
}
txs, err := client.GetAddressTransactions(context.Background(), &pb.GetAddressTransactionsRequest{
Address: resp.Block.TransactionData[0].GetTransaction().Outputs[0].Address,
})
if len(txs.ConfirmedTransactions) > 1 {
continue
}
_, err = client.GetUnspentOutput(context.Background(), &pb.GetUnspentOutputRequest{
Hash: resp.Block.TransactionData[0].GetTransaction().Hash,
Index: 0,
})
if err != nil {
continue
}
found = append(found, resp.Block.TransactionData[0].GetTransaction().Outputs[0].Address)
}
fmt.Printf("Found %d addrs in %s\n", len(found), time.Since(start))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment