func Input(nodeAddr, pubkey, amtS, nonceS, addr string) ([]byte, error) { pub, addrBytes, amt, nonce, err := checkCommon(nodeAddr, pubkey, addr, amtS, nonceS) if err != nil { return nil, err } txInput := types.TxInput{ Address: addrBytes, Amount: amt, Sequence: int(nonce), PubKey: pub, } n, errPtr := new(int64), new(error) buf := new(bytes.Buffer) txInput.WriteSignBytes(buf, n, errPtr) if *errPtr != nil { return nil, *errPtr } return buf.Bytes(), nil }
func validateInput(acc *acm.Account, signBytes []byte, in *types.TxInput) (err error) { // Check TxInput basic if err := in.ValidateBasic(); err != nil { return err } // Check signatures if !acc.PubKey.VerifyBytes(signBytes, in.Signature) { return types.ErrTxInvalidSignature } // Check sequences if acc.Sequence+1 != in.Sequence { return types.ErrTxInvalidSequence{ Got: in.Sequence, Expected: acc.Sequence + 1, } } // Check amount if acc.Balance < in.Amount { return types.ErrTxInsufficientFunds } return nil }
func checkInputPubKey(acc *acm.Account, in *types.TxInput) error { if acc.PubKey == nil { if in.PubKey == nil { return types.ErrTxUnknownPubKey } if !bytes.Equal(in.PubKey.Address(), acc.Address) { return types.ErrTxInvalidPubKey } acc.PubKey = in.PubKey } else { in.PubKey = nil } return nil }