-
Notifications
You must be signed in to change notification settings - Fork 0
/
miner.go
72 lines (55 loc) · 1.93 KB
/
miner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// miner.go
// Staring template for PointCoint miner.
//
// cs4501: Cryptocurrency Cafe
// University of Virginia, Spring 2015
// Project 2
//
package main
import (
"fmt"
"log"
"math/big"
"math/rand"
"github.com/PointCoin/btcjson"
"github.com/PointCoin/btcutil"
"github.com/PointCoin/pointcoind/blockchain"
)
const (
// This should match your settings in pointcoind.conf
rpcuser = "[your username]"
rpcpass = "[your password]"
// This file should exist if pointcoind was setup correctly
cert = "/home/ubuntu/.pointcoind/rpc.cert"
)
func main() {
// Setup the client using application constants, fail horribly if there's a problem
client := setupRpcClient(cert, rpcuser, rpcpass)
for { // Loop forever (you may want to do something smarter!)
// Get a new block template from pointcoind.
log.Printf("Requesting a block template\n")
template, err := client.GetBlockTemplate(&btcjson.TemplateRequest{})
if err != nil {
log.Fatal(err)
}
// The template returned by GetBlockTemplate provides these fields that
// you will need to use to create a new block:
// The hash of the previous block
prevHash := template.PreviousHash
// The difficulty target
difficulty := formatDiff(template.Bits)
// The height of the next block (number of blocks between genesis block and next block)
height := template.Height
// The transactions from the network
txs := formatTransactions(template.Transactions)
// These are configurable parameters to the coinbase transaction
msg := "Your computing ID" // replace with your UVa Computing ID (e.g., "dee2b")
a := "PsVSrUSQf72X6GWFQXJPxR7WSAPVRb1gWx" // replace with the address you want mining fees to go to (or leave it like this and Nick gets them)
coinbaseTx := CreateCoinbaseTx(height, a, msg)
txs = prepend(coinbaseTx.MsgTx(), txs)
merkleRoot := createMerkleRoot(txs)
// Finish the miner!
//block := CreateBlock(prevHash, merkleRoot, difficulty, nonce, txs)
}
}