Пример #1
0
func sign(c *cli.Context, tx data.Transaction, sequence int32) {
	priv, err := key.GenerateAccountKey(sequence)
	checkErr(err)
	id, err := key.GenerateAccountId(sequence)
	checkErr(err)
	pub, err := priv.PublicAccountKey()
	checkErr(err)
	base := tx.GetBase()
	base.Sequence = uint32(c.GlobalInt("sequence"))
	base.SigningPubKey = new(data.PublicKey)
	if c.GlobalInt("lastledger") > 0 {
		base.LastLedgerSequence = new(uint32)
		*base.LastLedgerSequence = uint32(c.GlobalInt("lastledger"))
	}
	if base.Flags == nil {
		base.Flags = new(data.TransactionFlag)
	}
	copy(base.Account[:], id.Payload())
	copy(base.SigningPubKey[:], pub.Payload())
	if c.GlobalString("fee") != "" {
		fee, err := data.NewNativeValue(int64(c.GlobalInt("fee")))
		checkErr(err)
		base.Fee = *fee
	}
	tx.GetBase().TxnSignature = &data.VariableLength{}
	checkErr(data.Sign(tx, priv))
}
Пример #2
0
func newTxBundle(v data.Transaction, insert string, flag Flag) (*bundle, error) {
	var (
		base   = v.GetBase()
		format = "%s %-11s %-8s %s%s %-34s %-9d "
		values = []interface{}{SignSymbol(v), base.GetType(), base.Fee, insert, MemoSymbol(v), base.Account, base.Sequence}
	)
	if flag&ShowTransactionId > 0 {
		txId, err := data.NodeId(v)
		if err != nil {
			return nil, err
		}
		format = "%s " + format
		values = append([]interface{}{txId}, values...)
	}
	switch tx := v.(type) {
	case *data.Payment:
		format += "=> %-34s %-60s %-60s"
		values = append(values, []interface{}{tx.Destination, tx.Amount, tx.SendMax}...)
	case *data.OfferCreate:
		format += "%-60s %-60s %-18s"
		values = append(values, []interface{}{tx.TakerPays, tx.TakerGets, tx.Ratio()}...)
	case *data.OfferCancel:
		format += "%-9d"
		values = append(values, tx.Sequence)
	case *data.AccountSet:
		format += "%-9d"
		values = append(values, tx.Sequence)
	case *data.TrustSet:
		format += "%-60s %d %d"
		values = append(values, tx.LimitAmount, tx.QualityIn, tx.QualityOut)
	}
	return &bundle{
		color:  txStyle,
		format: format,
		values: values,
		flag:   flag,
	}, nil
}
Пример #3
0
func MemoSymbol(tx data.Transaction) string {
	if len(tx.GetBase().Memos) > 0 {
		return "✐"
	}
	return " "
}