44 lines
1.7 KiB
Go
44 lines
1.7 KiB
Go
// Package tron implements the subset of TRON blockchain interaction required by
|
|
// the kisstron CLI wallet: key/address handling, HTTP node access, transaction
|
|
// building/signing/broadcasting and minimal TRC20 calls.
|
|
package tron
|
|
|
|
import "errors"
|
|
|
|
// Sentinel errors mirror tronpy.exceptions so API failures can be mapped the
|
|
// same way the original Python implementation does.
|
|
var (
|
|
ErrBadAddress = errors.New("invalid address")
|
|
ErrAddressNotFound = errors.New("account not found on-chain")
|
|
ErrBadKey = errors.New("invalid private key")
|
|
ErrBadSignature = errors.New("bad signature")
|
|
ErrBadHash = errors.New("wrong transaction hash length")
|
|
ErrTapos = errors.New("tapos error")
|
|
ErrTransaction = errors.New("transaction error")
|
|
ErrTvm = errors.New("tvm error")
|
|
ErrValidation = errors.New("validation error")
|
|
ErrAPI = errors.New("api error")
|
|
ErrNotFound = errors.New("not found")
|
|
ErrTransactionNotFound = errors.New("transaction not found")
|
|
ErrContractNotFound = errors.New("contract address not found")
|
|
)
|
|
|
|
// apiError carries a node message while unwrapping to a sentinel error, so its
|
|
// Error() string matches Python's `str(e)` (the bare message) and errors.Is
|
|
// still identifies the failure class.
|
|
type apiError struct {
|
|
sentinel error
|
|
msg string
|
|
}
|
|
|
|
func (e *apiError) Error() string { return e.msg }
|
|
func (e *apiError) Unwrap() error { return e.sentinel }
|
|
|
|
// wrapErr attaches a message to a sentinel error.
|
|
func wrapErr(sentinel error, msg string) error {
|
|
if msg == "" {
|
|
return sentinel
|
|
}
|
|
return &apiError{sentinel: sentinel, msg: msg}
|
|
}
|