MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / transferSQLChainTokenBalance

Method transferSQLChainTokenBalance

blockproducer/metastate.go:1013–1127  ·  view source on GitHub ↗
(transfer *types.Transfer)

Source from the content-addressed store, hash-verified

1011}
1012
1013func (s *metaState) transferSQLChainTokenBalance(transfer *types.Transfer) (err error) {
1014 if transfer.Signee == nil {
1015 err = ErrInvalidSender
1016 log.WithError(err).Warning("invalid signee in applyTransaction")
1017 return
1018 }
1019
1020 realSender, err := crypto.PubKeyHash(transfer.Signee)
1021 if err != nil {
1022 err = errors.Wrap(err, "applyTx failed")
1023 return
1024 }
1025
1026 if realSender != transfer.Sender {
1027 err = errors.Wrapf(ErrInvalidSender,
1028 "applyTx failed: real sender %s, sender %s", realSender, transfer.Sender)
1029 log.WithError(err).Warning("public key not match sender in applyTransaction")
1030 return
1031 }
1032
1033 var (
1034 sqlchain *types.SQLChainProfile
1035 account *types.Account
1036 ok bool
1037 )
1038 sqlchain, ok = s.loadSQLChainObject(transfer.Receiver.DatabaseID())
1039 if !ok {
1040 err = ErrDatabaseNotFound
1041 log.WithFields(log.Fields{
1042 "dbid": transfer.Receiver.DatabaseID(),
1043 "sender": transfer.Sender,
1044 }).WithError(err).Warning("database not exist in transferSQLChainTokenBalance")
1045 return
1046 }
1047 if sqlchain.TokenType != transfer.TokenType {
1048 err = ErrWrongTokenType
1049 log.WithFields(log.Fields{
1050 "dbid": transfer.Receiver.DatabaseID(),
1051 "sender": transfer.Sender,
1052 }).WithError(err).Warning("error token type in transferSQLChainTokenBalance")
1053 return
1054 }
1055 account, ok = s.loadAccountObject(realSender)
1056 if account.TokenBalance[transfer.TokenType] < transfer.Amount {
1057 err = ErrInsufficientBalance
1058 log.WithFields(log.Fields{
1059 "addr": account.Address,
1060 "amount": account.TokenBalance[transfer.TokenType],
1061 "transfer_amount": transfer.Amount,
1062 "token_type": transfer.TokenType,
1063 }).WithError(err).Warning("in transferSQLChainTokenBalance")
1064 return
1065 }
1066
1067 for _, user := range sqlchain.Users {
1068 if user.Address == transfer.Sender {
1069 // process arrears
1070 if user.Arrears > 0 {

Callers 1

applyTransactionMethod · 0.95

Calls 11

loadSQLChainObjectMethod · 0.95
loadAccountObjectMethod · 0.95
WithErrorFunction · 0.92
PubKeyHashFunction · 0.92
WithFieldsFunction · 0.92
minDepositFunction · 0.85
safeAddFunction · 0.85
WarningMethod · 0.80
DatabaseIDMethod · 0.80
WithErrorMethod · 0.80
EnableQueryMethod · 0.80

Tested by

no test coverage detected