Example #1
0
func InitTransaction() coin.Transaction {
	var tx coin.Transaction

	output := cipher.MustSHA256FromHex("043836eb6f29aaeb8b9bfce847e07c159c72b25ae17d291f32125e7f1912e2a0")
	tx.PushInput(output)

	for i := 0; i < 100; i++ {
		addr := cipher.MustDecodeBase58Address(AddrList[i])
		tx.PushOutput(addr, 1e12, 1) // 10e6*10e6
	}
	/*
		seckeys := make([]cipher.SecKey, 1)
		seckey := ""
		seckeys[0] = cipher.MustSecKeyFromHex(seckey)
		tx.SignInputs(seckeys)
	*/

	txs := make([]cipher.Sig, 1)
	sig := "ed9bd7a31fe30b9e2d53b35154233dfdf48aaaceb694a07142f84cdf4f5263d21b723f631817ae1c1f735bea13f0ff2a816e24a53ccb92afae685fdfc06724de01"
	txs[0] = cipher.MustSigFromHex(sig)
	tx.Sigs = txs

	tx.UpdateHeader()

	err := tx.Verify()

	if err != nil {
		log.Panic(err)
	}

	log.Printf("signature= %s", tx.Sigs[0].Hex())
	return tx
}
Example #2
0
func assertReadableTransactionHeader(t *testing.T,
	rth ReadableTransactionHeader, th coin.TransactionHeader) {
	assert.Equal(t, len(rth.Sigs), len(th.Sigs))
	assert.NotPanics(t, func() {
		for i, s := range rth.Sigs {
			assert.Equal(t, cipher.MustSigFromHex(s), th.Sigs[i])
		}
		assert.Equal(t, cipher.MustSHA256FromHex(rth.Hash), th.Hash)
	})
	assertJSONSerializability(t, &rth)
}
Example #3
0
func configureDaemon(c *Config) daemon.Config {
	//cipher.SetAddressVersion(c.AddressVersion)
	dc := daemon.NewConfig()
	dc.Peers.DataDirectory = c.DataDirectory
	dc.DHT.Disabled = c.DisableDHT
	dc.Peers.Disabled = c.DisablePEX
	dc.Daemon.DisableOutgoingConnections = c.DisableOutgoingConnections
	dc.Daemon.DisableIncomingConnections = c.DisableIncomingConnections
	dc.Daemon.DisableNetworking = c.DisableNetworking
	dc.Daemon.Port = c.Port
	dc.Daemon.Address = c.Address
	dc.Daemon.LocalhostOnly = c.LocalhostOnly
	if c.OutgoingConnectionsRate == 0 {
		c.OutgoingConnectionsRate = time.Millisecond
	}
	dc.Daemon.OutgoingRate = c.OutgoingConnectionsRate
	dc.Visor.Config.IsMaster = c.MasterChain
	dc.Visor.Config.CanSpend = c.CanSpend
	dc.Visor.Config.WalletDirectory = c.WalletDirectory
	dc.Visor.Config.BlockchainFile = c.BlockchainFile
	dc.Visor.Config.BlockSigsFile = c.BlockSigsFile
	dc.Visor.Config.GenesisSignature = cipher.MustSigFromHex(c.GenesisSignature)
	dc.Visor.Config.GenesisTimestamp = c.GenesisTimestamp
	dc.Visor.Config.WalletConstructor = wallet.NewDeterministicWallet
	if c.MasterChain {
		// The master chain should be reluctant to expire transactions
		dc.Visor.Config.UnconfirmedRefreshRate = time.Hour * 4096
	}

	dc.Visor.MasterKeysFile = c.MasterKeys
	if c.MasterChain {
		// Will panic if fails
		dc.Visor.LoadMasterKeys()
	} else {
		w := wallet.ReadableWalletEntryFromPubkey(c.MasterPublic)
		dc.Visor.Config.MasterKeys = wallet.WalletEntryFromReadable(&w)
	}
	return dc
}