github.com/incognitochain/go-incognito-sdk@v1.0.1/privacy/error.go (about) 1 package privacy 2 3 import ( 4 "fmt" 5 "github.com/pkg/errors" 6 ) 7 8 const ( 9 UnexpectedErr = iota 10 InvalidOutputValue 11 MarshalPaymentProofErr 12 UnmarshalPaymentProofErr 13 SetBytesProofErr 14 EncryptOutputCoinErr 15 DecryptOutputCoinErr 16 DecompressTransmissionKeyErr 17 VerifySerialNumberNoPrivacyProofFailedErr 18 VerifyCoinCommitmentInputFailedErr 19 VerifyCoinCommitmentOutputFailedErr 20 VerifyAmountNoPrivacyFailedErr 21 VerifyOneOutOfManyProofFailedErr 22 VerifySerialNumberPrivacyProofFailedErr 23 VerifyAggregatedProofFailedErr 24 VerifyAmountPrivacyFailedErr 25 CalInnerProductErr 26 ProveSerialNumberNoPrivacyErr 27 ProveOneOutOfManyErr 28 ProveSerialNumberPrivacyErr 29 ProveAggregatedRangeErr 30 InvalidInputToSetBytesErr 31 CommitNewOutputCoinNoPrivacyErr 32 ConvertMultiSigToBytesErr 33 SignMultiSigErr 34 InvalidLengthMultiSigErr 35 InvalidMultiSigErr 36 ) 37 38 var ErrCodeMessage = map[int]struct { 39 Code int 40 Message string 41 }{ 42 UnexpectedErr: {-9000, "Unexpected error"}, 43 44 InvalidOutputValue: {-9001, "Invalid output value"}, 45 MarshalPaymentProofErr: {-9002, "Marshal payment proof error"}, 46 UnmarshalPaymentProofErr: {-9003, "Unmarshal payment proof error"}, 47 SetBytesProofErr: {-9004, "Set bytes payment proof error"}, 48 EncryptOutputCoinErr: {-9005, "Encrypt output coins error"}, 49 DecryptOutputCoinErr: {-9006, "Decrypt output coins error"}, 50 DecompressTransmissionKeyErr: {-9007, "Can not decompress transmission key error"}, 51 CalInnerProductErr: {-9008, "Calculate inner product between two vectors error"}, 52 InvalidInputToSetBytesErr: {-9009, "Length of input data is zero, can not set bytes"}, 53 CommitNewOutputCoinNoPrivacyErr: {-9010, "Can not commit output coin's details when creating tx without privacy"}, 54 ConvertMultiSigToBytesErr: {-9011, "Can not convert multi sig to bytes array"}, 55 SignMultiSigErr: {-9012, "Can not sign multi sig"}, 56 InvalidLengthMultiSigErr: {-9013, "Invalid length of multi sig signature"}, 57 InvalidMultiSigErr: {-9014, "invalid multiSig for converting to bytes array"}, 58 59 ProveSerialNumberNoPrivacyErr: {-9100, "Proving serial number no privacy proof error"}, 60 ProveOneOutOfManyErr: {-9101, "Proving one out of many proof error"}, 61 ProveSerialNumberPrivacyErr: {-9102, "Proving serial number privacy proof error"}, 62 ProveAggregatedRangeErr: {-9103, "Proving aggregated range proof error"}, 63 64 VerifySerialNumberNoPrivacyProofFailedErr: {-9201, "Verify serial number no privacy proof failed"}, 65 VerifyCoinCommitmentInputFailedErr: {-9202, "Verify coin commitment of input coin failed"}, 66 VerifyCoinCommitmentOutputFailedErr: {-9203, "Verify coin commitment of output coin failed"}, 67 VerifyAmountNoPrivacyFailedErr: {-9204, "Sum of input coins' amount is not equal sum of output coins' amount"}, 68 VerifyOneOutOfManyProofFailedErr: {-9205, "Verify one out of many proof failed"}, 69 VerifySerialNumberPrivacyProofFailedErr: {-9206, "Verify serial number privacy proof failed"}, 70 VerifyAggregatedProofFailedErr: {-9207, "Verify aggregated proof failed"}, 71 VerifyAmountPrivacyFailedErr: {-9208, "Sum of input coins' amount is not equal sum of output coins' amount when creating private tx"}, 72 } 73 74 type PrivacyError struct { 75 Code int 76 Message string 77 err error 78 } 79 80 func (e PrivacyError) Error() string { 81 return fmt.Sprintf("%+v: %+v %+v", e.Code, e.Message, e.err) 82 } 83 84 func (e PrivacyError) GetCode() int { 85 return e.Code 86 } 87 88 func NewPrivacyErr(key int, err error) *PrivacyError { 89 return &PrivacyError{ 90 err: errors.Wrap(err, ErrCodeMessage[key].Message), 91 Code: ErrCodeMessage[key].Code, 92 Message: ErrCodeMessage[key].Message, 93 } 94 }