func GetTransactions() ([]*Transaction, error) { fmt.Println("GetTransactions") keys, transactions, err := Wallet.GetTransactions() if err != nil { fmt.Printf("Error - %v\n", err) return nil, err } fmt.Printf("%v, %v\n", len(keys), len(transactions)) /* addressMap, err := GetAddressMapByAddress() if err != nil { return nil, err }*/ for _, v := range transactions { //var FactoidBalanceDelta float64 = 0 // var ECBalanceDelta float64 = 0 ins := v.GetInputs() for _, i := range ins { fmt.Printf("%v\n", i.String()) } } return nil, nil }
// Specifying a fee overrides either not being connected, or the current fee. // Params: // key (limit printout to this key) // fee (specify the transation fee) func GetTransactionsj(ctx *web.Context) (string, error) { connected := true var _ = connected keys, transactions, _ := Wallet.GetTransactions() type pair struct { Key string TransID string } var trans []*pair for i, t := range transactions { p := new(pair) p.Key = strings.TrimRight(string(keys[i]), "\u0000") p.TransID = t.GetSigHash().String() trans = append(trans, p) } return common.EncodeJSONString(trans) }
// Specifying a fee overrides either not being connected, or the current fee. // Params: // key (limit printout to this key) // fee (specify the transation fee) func GetTransactions(ctx *web.Context) ([]byte, error) { connected := true var _ = connected exch, err := GetFee(ctx) // The Fee will be zero if we have no connection. if err != nil { connected = false } keys, transactions, err := Wallet.GetTransactions() if err != nil { return nil, err } var out bytes.Buffer for i, trans := range transactions { fee, _ := trans.CalculateFee(uint64(exch)) cprt := "" cin, err := trans.TotalInputs() if err != nil { cprt = cprt + err.Error() } cout, err := trans.TotalOutputs() if err != nil { cprt = cprt + err.Error() } cecout, err := trans.TotalECs() if err != nil { cprt = cprt + err.Error() } if len(cprt) == 0 { v := int64(cin) - int64(cout) - int64(cecout) sign := "" if v < 0 { sign = "-" v = -v } cprt = fmt.Sprintf(" Currently will pay: %s%s", sign, strings.TrimSpace(fct.ConvertDecimal(uint64(v)))) if sign == "-" || fee > uint64(v) { cprt = cprt + "\n\nWARNING: Currently your transaction fee may be too low" } } out.WriteString(fmt.Sprintf("%s: Fee Due: %s %s\n\n%s\n", strings.TrimSpace(strings.TrimRight(string(keys[i]), "\u0000")), strings.TrimSpace(fct.ConvertDecimal(fee)), cprt, transactions[i].String())) } output := out.Bytes() // now look for the addresses, and replace them with our names. (the transactions // in flight also have a Factom address... We leave those alone. names, vs := Wallet.GetWalletNames() for i, name := range names { we, ok := vs[i].(wallet.IWalletEntry) if !ok { return nil, fmt.Errorf("Database is corrupt") } address, err := we.GetAddress() if err != nil { continue } // We shouldn't get any of these, but ignore them if we do. adrstr := []byte(hex.EncodeToString(address.Bytes())) output = bytes.Replace(output, adrstr, name, -1) } return output, nil }