本文整理匯總了Golang中github.com/NebulousLabs/Sia/types.Currency.Big方法的典型用法代碼示例。如果您正苦於以下問題:Golang Currency.Big方法的具體用法?Golang Currency.Big怎麽用?Golang Currency.Big使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NebulousLabs/Sia/types.Currency
的用法示例。
在下文中一共展示了Currency.Big方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: currencyUnits
// currencyUnits converts a types.Currency to a string with human-readable
// units. The unit used will be the largest unit that results in a value
// greater than 1. The value is rounded to 4 significant digits.
func currencyUnits(c types.Currency) string {
pico := types.SiacoinPrecision.Div64(1e12)
if c.Cmp(pico) < 0 {
return c.String() + " H"
}
// iterate until we find a unit greater than c
mag := pico
unit := ""
for _, unit = range []string{"pS", "nS", "uS", "mS", "SC", "KS", "MS", "GS", "TS"} {
if c.Cmp(mag.Mul64(1e3)) < 0 {
break
} else if unit != "TS" {
// don't want to perform this multiply on the last iter; that
// would give us 1.235 TS instead of 1235 TS
mag = mag.Mul64(1e3)
}
}
num := new(big.Rat).SetInt(c.Big())
denom := new(big.Rat).SetInt(mag.Big())
res, _ := new(big.Rat).Mul(num, denom.Inv(denom)).Float64()
return fmt.Sprintf("%.4g %s", res, unit)
}
示例2: wallettransactionscmd
// wallettransactionscmd lists all of the transactions related to the wallet,
// providing a net flow of siacoins and siafunds for each.
func wallettransactionscmd() {
wtg := new(api.WalletTransactionsGET)
err := getAPI("/wallet/transactions?startheight=0&endheight=10000000", wtg)
if err != nil {
fmt.Println("Could not fetch transaction history:", err)
return
}
fmt.Println(" [height] [transaction id] [net siacoins] [net siafunds]")
txns := append(wtg.ConfirmedTransactions, wtg.UnconfirmedTransactions...)
for _, txn := range txns {
// Determine the number of outgoing siacoins and siafunds.
var outgoingSiacoins types.Currency
var outgoingSiafunds types.Currency
for _, input := range txn.Inputs {
if input.FundType == types.SpecifierSiacoinInput && input.WalletAddress {
outgoingSiacoins = outgoingSiacoins.Add(input.Value)
}
if input.FundType == types.SpecifierSiafundInput && input.WalletAddress {
outgoingSiafunds = outgoingSiafunds.Add(input.Value)
}
}
// Determine the number of incoming siacoins and siafunds.
var incomingSiacoins types.Currency
var incomingSiafunds types.Currency
for _, output := range txn.Outputs {
if output.FundType == types.SpecifierMinerPayout {
incomingSiacoins = incomingSiacoins.Add(output.Value)
}
if output.FundType == types.SpecifierSiacoinOutput && output.WalletAddress {
incomingSiacoins = incomingSiacoins.Add(output.Value)
}
if output.FundType == types.SpecifierSiafundOutput && output.WalletAddress {
incomingSiafunds = incomingSiafunds.Add(output.Value)
}
}
// Convert the siacoins to a float.
incomingSiacoinsFloat, _ := new(big.Rat).SetFrac(incomingSiacoins.Big(), types.SiacoinPrecision.Big()).Float64()
outgoingSiacoinsFloat, _ := new(big.Rat).SetFrac(outgoingSiacoins.Big(), types.SiacoinPrecision.Big()).Float64()
// Print the results.
if txn.ConfirmationHeight < 1e9 {
fmt.Printf("%12v", txn.ConfirmationHeight)
} else {
fmt.Printf(" unconfirmed")
}
fmt.Printf("%67v%15.2f SC", txn.TransactionID, incomingSiacoinsFloat-outgoingSiacoinsFloat)
// For siafunds, need to avoid having a negative types.Currency.
if incomingSiafunds.Cmp(outgoingSiafunds) >= 0 {
fmt.Printf("%14v SF\n", incomingSiafunds.Sub(outgoingSiafunds))
} else {
fmt.Printf("-%14v SF\n", outgoingSiafunds.Sub(incomingSiafunds))
}
}
}