errors.go raw

   1  package wallet
   2  
   3  import (
   4  	"errors"
   5  	
   6  	"github.com/p9c/p9/pkg/btcjson"
   7  )
   8  
   9  // TODO(jrick): There are several error paths which 'replace' various errors
  10  //  with a more appropiate error from the json package.  Create a map of
  11  //  these replacements so they can be handled once after an RPC handler has
  12  //  returned and before the error is marshaled.
  13  //
  14  // BTCJSONError types to simplify the reporting of specific categories of
  15  // errors, and their *json.RPCError creation.
  16  type (
  17  	// DeserializationError describes a failed deserializaion due to bad user input. It corresponds to
  18  	// json.ErrRPCDeserialization.
  19  	DeserializationError struct {
  20  		error
  21  	}
  22  	// InvalidParameterError describes an invalid parameter passed by the user. It corresponds to
  23  	// json.ErrRPCInvalidParameter.
  24  	InvalidParameterError struct {
  25  		error
  26  	}
  27  	// ParseError describes a failed parse due to bad user input. It corresponds to json.ErrRPCParse.
  28  	ParseError struct {
  29  		error
  30  	}
  31  )
  32  
  33  // Errors variables that are defined once here to avoid duplication below.
  34  var (
  35  	ErrNeedPositiveAmount = InvalidParameterError{
  36  		errors.New("amount must be positive"),
  37  	}
  38  	ErrNeedPositiveMinconf = InvalidParameterError{
  39  		errors.New("minconf must be positive"),
  40  	}
  41  	ErrAddressNotInWallet = btcjson.RPCError{
  42  		Code:    btcjson.ErrRPCWallet,
  43  		Message: "address not found in wallet",
  44  	}
  45  	ErrAccountNameNotFound = btcjson.RPCError{
  46  		Code:    btcjson.ErrRPCWalletInvalidAccountName,
  47  		Message: "account name not found",
  48  	}
  49  	ErrUnloadedWallet = btcjson.RPCError{
  50  		Code:    btcjson.ErrRPCWallet,
  51  		Message: "Request requires a wallet but wallet has not loaded yet",
  52  	}
  53  	ErrWalletUnlockNeeded = btcjson.RPCError{
  54  		Code:    btcjson.ErrRPCWalletUnlockNeeded,
  55  		Message: "Enter the wallet passphrase with walletpassphrase first",
  56  	}
  57  	ErrNotImportedAccount = btcjson.RPCError{
  58  		Code:    btcjson.ErrRPCWallet,
  59  		Message: "imported addresses must belong to the imported account",
  60  	}
  61  	ErrNoTransactionInfo = btcjson.RPCError{
  62  		Code:    btcjson.ErrRPCNoTxInfo,
  63  		Message: "No information for transaction",
  64  	}
  65  	ErrReservedAccountName = btcjson.RPCError{
  66  		Code:    btcjson.ErrRPCInvalidParameter,
  67  		Message: "Account name is reserved by RPC server",
  68  	}
  69  )
  70