コード例 #1
0
ファイル: entry.go プロジェクト: skycoin/skycoin
func WalletEntryFromReadable(w *ReadableWalletEntry) WalletEntry {
	// SimpleWallet entries are shared as a form of identification, the secret key
	// is not required
	// TODO -- fix lib/base58 to not panic on invalid input -- should
	// return error, so we can detect a broken wallet.

	if w.Address == "" {
		//log.Panic("ReadableWalletEntry has no Address")
	}
	var s cipher.SecKey
	if w.Secret != "" {
		s = cipher.MustSecKeyFromHex(w.Secret)
	}

	//regen from the private key
	//redundant/
	if w.Address == "" {
		addr := cipher.AddressFromSecKey(s)
		pub := cipher.PubKeyFromSecKey(s)

		return WalletEntry{
			Address: addr,
			Public:  pub,
			Secret:  s,
		}
	}

	return WalletEntry{
		Address: cipher.MustDecodeBase58Address(w.Address),
		Public:  cipher.MustPubKeyFromHex(w.Public),
		Secret:  s,
	}
}
コード例 #2
0
ファイル: wallet.go プロジェクト: skycoin/skycoin
func getBalanceHandler(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		if r.Method == "GET" {
			addrsParam := r.URL.Query().Get("addrs")
			addrsStr := strings.Split(addrsParam, ",")
			addrs := make([]cipher.Address, len(addrsStr))
			addrSet := make(map[cipher.Address]byte)
			for i, addr := range addrsStr {
				addrs[i] = cipher.MustDecodeBase58Address(addr)
				addrSet[addrs[i]] = byte(1)
			}

			v := gateway.D.Visor.Visor
			auxs := v.Blockchain.GetUnspent().AllForAddresses(addrs)
			unspent := v.Blockchain.GetUnspent()
			puxs := v.Unconfirmed.SpendsForAddresses(unspent, addrSet)

			coins1, hours1 := v.AddressBalance(auxs)
			coins2, hours2 := v.AddressBalance(auxs.Sub(puxs))

			confirmed := wallet.Balance{coins1, hours1}
			predicted := wallet.Balance{coins2, hours2}
			bal := struct {
				Confirmed wallet.Balance `json:"confirmed"`
				Predicted wallet.Balance `json:"predicted"`
			}{
				Confirmed: confirmed,
				Predicted: predicted,
			}

			wh.SendOr404(w, bal)
		}
	}
}
コード例 #3
0
ファイル: skycoin.go プロジェクト: keepwalking1234/skycoin
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
}
コード例 #4
0
ファイル: blockchain.go プロジェクト: skycoin/skycoin
//main net config
func init() {
	MainNet.PubKey = coin.MustPubKeyFromHex("02bb0be2976457d2e30a9aea9b0057b0eb9d1ad6509ef743c25c737f24d6241a99")
	//TestNet.GenesisSignature = coin.MustSigFromHex()
	MainNet.GenesisAddress = cipher.MustDecodeBase58Address("26HbgWGwrToLZ6aX8VHtQmH4SPj4baQ5S3p")
	MainNet.GenesisTime = 1392584987 //set time
	MainNet.GenesisCoins = 100e6     //100 million
}
コード例 #5
0
ファイル: coin.go プロジェクト: skycoin/skycoin-exchange
func (cn coinEx) makeTxOut(addr string, coins uint64, hours uint64) skycoin.TxOut {
	out := skycoin.TxOut{}
	out.Address = cipher.MustDecodeBase58Address(addr)
	out.Coins = coins
	out.Hours = hours
	return out
}
コード例 #6
0
ファイル: create_rawtx.go プロジェクト: skycoin/skycoin
func mustMakeUtxoOutput(addr string, amount uint64, hours uint64) coin.TransactionOutput {
	uo := coin.TransactionOutput{}
	uo.Address = cipher.MustDecodeBase58Address(addr)
	uo.Coins = amount
	uo.Hours = hours
	return uo
}
コード例 #7
0
ファイル: blockchain.go プロジェクト: skycoin/skycoin
//testnet config
func init() {
	TestNet.PubKey = coin.MustPubKeyFromHex("025a3b22eb1e132a01f485119ae343342d92ab8599d9ad613a76e3b27f878bca8b")
	//TestNet.GenesisSignature = coin.MustSigFromHex()
	TestNet.GenesisAddress = cipher.MustDecodeBase58Address("26HbgWGwrToLZ6aX8VHtQmH4SPj4baQ5S3p")
	TestNet.GenesisTime = 1392584986 //set time
	TestNet.GenesisCoins = 1e12      //almost as many as Ripple
	//TestNet.GenesisSignature = coin.MustSigFromHex()
}
コード例 #8
0
ファイル: readable_test.go プロジェクト: JmAbuDabi/skycoin
func assertReadableTransactionOutput(t *testing.T,
	rto ReadableTransactionOutput, to coin.TransactionOutput) {
	assert.NotPanics(t, func() {
		assert.Equal(t, cipher.MustDecodeBase58Address(rto.Address),
			to.Address)
	})
	assert.Equal(t, rto.Coins, to.Coins)
	assert.Equal(t, rto.Hours, to.Hours)
	assertJSONSerializability(t, &rto)
}
コード例 #9
0
ファイル: historydb_test.go プロジェクト: skycoin/skycoin
func testEngine(t *testing.T, tds []testData, bc historydb.Blockchainer, hdb *historydb.HistoryDB, db *bolt.DB) {
	for i, td := range tds {
		b, tx, err := addBlock(bc, td, _incTime*(uint64(i)+1))
		if err != nil {
			t.Fatal(err)
		}
		// update the next block test data.
		if i+1 < len(tds) {
			// update UxOut of next test data.
			tds[i+1].Vin.TxID = tx.Hash()
			tds[i+1].PreBlockHash = b.HashHeader()
		}

		if err := hdb.ProcessBlock(b); err != nil {
			t.Fatal(err)
		}

		// check tx
		txInBkt := historydb.Transaction{}
		k := tx.Hash()
		if err := getBucketValue(db, transactionBkt, k[:], &txInBkt); err != nil {
			t.Fatal(err)
		}
		assert.Equal(t, &txInBkt.Tx, tx)

		// check outputs
		for _, o := range td.Vouts {
			ux, err := getUx(bc, uint64(i+1), tx.Hash(), o.ToAddr)
			if err != nil {
				t.Fatal(err)
			}

			uxInDB := historydb.UxOut{}
			uxKey := ux.Hash()
			if err = getBucketValue(db, outputBkt, uxKey[:], &uxInDB); err != nil {
				t.Fatal(err)
			}
			assert.Equal(t, &uxInDB.Out, ux)
		}

		// check addr in
		for _, o := range td.Vouts {
			addr := cipher.MustDecodeBase58Address(o.ToAddr)
			uxHashes := []cipher.SHA256{}
			if err := getBucketValue(db, addressInBkt, addr.Bytes(), &uxHashes); err != nil {
				t.Fatal(err)
			}
			assert.Equal(t, len(uxHashes), td.AddrInNum[o.ToAddr])
		}
	}
}
コード例 #10
0
ファイル: uxout_test.go プロジェクト: skycoin/skycoin
func newUxOutMock() (*GatewayerMock, func(addr string) []*historydb.UxOutJSON) {
	m := NewGatewayerMock()
	uxoutJSON := `[
                {
                    "uxid": "cc816392cef53a5b75f91bc3fb8155f133907c8ce7f6540507ab30e0456aec3e",
                    "time": 1482042899,
                    "src_block_seq": 562,
                    "src_tx": "ec9e876d4bb33beec203de769b0d3b23de21052de0e4df06b1444bcfec773c46",
                    "owner_address": "2kmKohJrwURrdcVtDNaWK6hLCNsWWbJhTqT",
                    "coins": 1000000,
                    "hours": 0,
                    "spent_block_seq": 563,
                    "spent_tx": "31a21a4dd8331ce68756ddbb21f2c66279d5f5526e936f550e49e29b840ac1ff"
                }
            ]`
	mockData := map[string]struct {
		ret []*historydb.UxOutJSON
		err error
	}{
		"2kmKohJrwURrdcVtDNaWK6hLCNsWWbJhTqT": {
			decodeUxJSON(uxoutJSON),
			nil,
		},
		"fyqX5YuwXMUs4GEUE3LjLyhrqvNztFHQ4B": {
			nil,
			errors.New("internal server error"),
		},
	}

	for addr, d := range mockData {
		a := cipher.MustDecodeBase58Address(addr)
		m.On("GetAddrUxOuts", a).Return(d.ret, d.err)
	}

	f := func(addr string) []*historydb.UxOutJSON {
		return mockData[addr].ret
	}
	return m, f
}