Ejemplo n.º 1
0
func (frh *FundraiserHandler) Process(msg *Msg, err error) {
	pack := msg.msg.(*mscutil.FundraiserTransaction)

	// Get the current balance sheet map, where the key is the currency id and the value the amount
	sheet := frh.db.GetAccount(pack.Addr)

	str := strings.Split(dec.NewDecInt64(0).Mul(pack.Value, dec.NewDecInt64(1e8)).String(), ".")[0]
	res, _ := big.NewInt(0).SetString(str, 10)
	dec := res.Uint64()

	sheet[1] += dec
	sheet[2] += dec

	// Save the key back to the db
	frh.db.PutAccount(pack.Addr, sheet)
	sheet = frh.db.GetAccount(pack.Addr)
}
Ejemplo n.º 2
0
func NewFundraiserTransaction(addr Address, value int64, time int64) (*FundraiserTransaction, error) {
	tx := &FundraiserTransaction{
		Addr: addr.Addr,
		Time: time,
	}

	// Base line amount bought from fundraiser, 1 btc gets you 100 msc
	mastercoinBought := dec.NewDecInt64((value * 100))
	mastercoinBought.Quo(mastercoinBought, dec.NewDecInt64(1e8), dec.Scale(18), dec.RoundHalfUp)

	fmt.Println("Baseline MSC Bought:", mastercoinBought)

	// Bonus amount received
	diff := dec.NewDecInt64(FundraiserEndTime - time)
	timeDifference := diff.Quo(diff, dec.NewDecInt64(604800), dec.Scale(18), dec.RoundHalfUp)

	fmt.Println("Time difference", timeDifference)

	if timeDifference.Cmp(dec.NewDecInt64(0)) > 0 {
		// bought += bought * (timediff * 0.1)

		x := new(dec.Dec)
		x.SetString("0.1")

		ratio := new(dec.Dec).Mul(timeDifference, x)
		fmt.Println("Ratio:", ratio)
		bonus := new(dec.Dec).Mul(ratio, mastercoinBought)
		bonus.Round(bonus, dec.Scale(18), dec.RoundDown)

		mastercoinBought.Add(mastercoinBought, bonus)
		mastercoinBought.Round(mastercoinBought, dec.Scale(8), dec.RoundHalfUp)
	}

	tx.Value = mastercoinBought

	Logger.Println("Created fundraiser transaction", tx)

	return tx, nil
}