user_wallet.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. package models
  2. import (
  3. "database/sql"
  4. "time"
  5. "github.com/google/uuid"
  6. "github.com/guregu/null"
  7. "gorm.io/gorm"
  8. )
  9. var (
  10. _ = time.Second
  11. _ = sql.LevelDefault
  12. _ = null.Bool{}
  13. _ = uuid.UUID{}
  14. )
  15. /*
  16. DB Table Details
  17. -------------------------------------
  18. CREATE TABLE `user_wallet` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `user_id` bigint(20) unsigned NOT NULL,
  21. `address` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  22. `private_key` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  23. `check_sum` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  24. `enc_version` int(11) NOT NULL DEFAULT '1',
  25. `certification_code` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  26. `request_currency` enum('default','eth','mf','mr') COLLATE utf8mb4_bin NOT NULL DEFAULT 'default',
  27. `request_balance` double DEFAULT NULL,
  28. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  29. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  30. `deleted_at` timestamp NULL DEFAULT NULL,
  31. PRIMARY KEY (`id`),
  32. UNIQUE KEY `id_UNIQUE` (`id`),
  33. UNIQUE KEY `private_key_UNIQUE` (`private_key`),
  34. KEY `fk_user_wallet_user1_idx` (`user_id`),
  35. CONSTRAINT `fk_user_wallet_user1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  36. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  37. JSON Sample
  38. -------------------------------------
  39. { "id": 3, "user_id": 55, "address": "vlxMwpHwhGhRcjvMpqsLZKrHC", "private_key": "INPnlZdPThimnScmGRRLCAgcY", "check_sum": "yvRhoXwAoHuiiqNIbxfGJWdll", "enc_version": 92, "certification_code": "MlBNjXqESDlisqhSbjMiyWohX", "request_currency": "oINxnvEbHWyvHdKVkcmugTuef", "request_balance": 0.5502714698436856, "created_at": "2042-02-02T02:03:25.520358736+09:00", "updated_at": "2247-08-09T00:39:55.890194209+09:00", "deleted_at": "2312-06-02T18:55:31.336393419+09:00"}
  40. Comments
  41. -------------------------------------
  42. [ 0] column is set for unsigned
  43. [ 1] column is set for unsigned
  44. */
  45. // UserWallet struct is a row record of the user_wallet table in the metarare database
  46. type UserWallet struct {
  47. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  48. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  49. //[ 1] user_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  50. UserID uint64 `gorm:"column:user_id;type:ubigint;" json:"user_id"`
  51. //[ 2] address varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  52. Address string `gorm:"column:address;type:varchar;size:256;" json:"address"`
  53. //[ 3] private_key varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  54. PrivateKey string `gorm:"column:private_key;type:varchar;size:256;" json:"private_key"`
  55. //[ 4] check_sum varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  56. CheckSum string `gorm:"column:check_sum;type:varchar;size:256;" json:"check_sum"`
  57. //[ 5] enc_version int null: false primary: false isArray: false auto: false col: int len: -1 default: [1]
  58. EncVersion int32 `gorm:"column:enc_version;type:int;default:1;" json:"enc_version"`
  59. //[ 6] certification_code varchar(256) null: true primary: false isArray: false auto: false col: varchar len: 256 default: []
  60. CertificationCode null.String `gorm:"column:certification_code;type:varchar;size:256;" json:"certification_code"`
  61. //[ 7] request_currency char(7) null: false primary: false isArray: false auto: false col: char len: 7 default: [default]
  62. RequestCurrency string `gorm:"column:request_currency;type:char;size:7;default:default;" json:"request_currency"`
  63. //[ 8] request_balance double null: true primary: false isArray: false auto: false col: double len: -1 default: []
  64. RequestBalance null.Float `gorm:"column:request_balance;type:double;" json:"request_balance"`
  65. //[ 9] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  66. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  67. //[10] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  68. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  69. //[11] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  70. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  71. }
  72. var user_walletTableInfo = &TableInfo{
  73. Name: "user_wallet",
  74. Columns: []*ColumnInfo{
  75. &ColumnInfo{
  76. Index: 0,
  77. Name: "id",
  78. Comment: ``,
  79. Notes: `column is set for unsigned`,
  80. Nullable: false,
  81. DatabaseTypeName: "ubigint",
  82. DatabaseTypePretty: "ubigint",
  83. IsPrimaryKey: true,
  84. IsAutoIncrement: true,
  85. IsArray: false,
  86. ColumnType: "ubigint",
  87. ColumnLength: -1,
  88. GoFieldName: "ID",
  89. GoFieldType: "uint64",
  90. JSONFieldName: "id",
  91. ProtobufFieldName: "id",
  92. ProtobufType: "uint64",
  93. ProtobufPos: 1,
  94. },
  95. &ColumnInfo{
  96. Index: 1,
  97. Name: "user_id",
  98. Comment: ``,
  99. Notes: `column is set for unsigned`,
  100. Nullable: false,
  101. DatabaseTypeName: "ubigint",
  102. DatabaseTypePretty: "ubigint",
  103. IsPrimaryKey: false,
  104. IsAutoIncrement: false,
  105. IsArray: false,
  106. ColumnType: "ubigint",
  107. ColumnLength: -1,
  108. GoFieldName: "UserID",
  109. GoFieldType: "uint64",
  110. JSONFieldName: "user_id",
  111. ProtobufFieldName: "user_id",
  112. ProtobufType: "uint64",
  113. ProtobufPos: 2,
  114. },
  115. &ColumnInfo{
  116. Index: 2,
  117. Name: "address",
  118. Comment: ``,
  119. Notes: ``,
  120. Nullable: false,
  121. DatabaseTypeName: "varchar",
  122. DatabaseTypePretty: "varchar(256)",
  123. IsPrimaryKey: false,
  124. IsAutoIncrement: false,
  125. IsArray: false,
  126. ColumnType: "varchar",
  127. ColumnLength: 256,
  128. GoFieldName: "Address",
  129. GoFieldType: "string",
  130. JSONFieldName: "address",
  131. ProtobufFieldName: "address",
  132. ProtobufType: "string",
  133. ProtobufPos: 3,
  134. },
  135. &ColumnInfo{
  136. Index: 3,
  137. Name: "private_key",
  138. Comment: ``,
  139. Notes: ``,
  140. Nullable: false,
  141. DatabaseTypeName: "varchar",
  142. DatabaseTypePretty: "varchar(256)",
  143. IsPrimaryKey: false,
  144. IsAutoIncrement: false,
  145. IsArray: false,
  146. ColumnType: "varchar",
  147. ColumnLength: 256,
  148. GoFieldName: "PrivateKey",
  149. GoFieldType: "string",
  150. JSONFieldName: "private_key",
  151. ProtobufFieldName: "private_key",
  152. ProtobufType: "string",
  153. ProtobufPos: 4,
  154. },
  155. &ColumnInfo{
  156. Index: 4,
  157. Name: "check_sum",
  158. Comment: ``,
  159. Notes: ``,
  160. Nullable: false,
  161. DatabaseTypeName: "varchar",
  162. DatabaseTypePretty: "varchar(256)",
  163. IsPrimaryKey: false,
  164. IsAutoIncrement: false,
  165. IsArray: false,
  166. ColumnType: "varchar",
  167. ColumnLength: 256,
  168. GoFieldName: "CheckSum",
  169. GoFieldType: "string",
  170. JSONFieldName: "check_sum",
  171. ProtobufFieldName: "check_sum",
  172. ProtobufType: "string",
  173. ProtobufPos: 5,
  174. },
  175. &ColumnInfo{
  176. Index: 5,
  177. Name: "enc_version",
  178. Comment: ``,
  179. Notes: ``,
  180. Nullable: false,
  181. DatabaseTypeName: "int",
  182. DatabaseTypePretty: "int",
  183. IsPrimaryKey: false,
  184. IsAutoIncrement: false,
  185. IsArray: false,
  186. ColumnType: "int",
  187. ColumnLength: -1,
  188. GoFieldName: "EncVersion",
  189. GoFieldType: "int32",
  190. JSONFieldName: "enc_version",
  191. ProtobufFieldName: "enc_version",
  192. ProtobufType: "int32",
  193. ProtobufPos: 6,
  194. },
  195. &ColumnInfo{
  196. Index: 6,
  197. Name: "certification_code",
  198. Comment: ``,
  199. Notes: ``,
  200. Nullable: true,
  201. DatabaseTypeName: "varchar",
  202. DatabaseTypePretty: "varchar(256)",
  203. IsPrimaryKey: false,
  204. IsAutoIncrement: false,
  205. IsArray: false,
  206. ColumnType: "varchar",
  207. ColumnLength: 256,
  208. GoFieldName: "CertificationCode",
  209. GoFieldType: "null.String",
  210. JSONFieldName: "certification_code",
  211. ProtobufFieldName: "certification_code",
  212. ProtobufType: "string",
  213. ProtobufPos: 7,
  214. },
  215. &ColumnInfo{
  216. Index: 7,
  217. Name: "request_currency",
  218. Comment: ``,
  219. Notes: ``,
  220. Nullable: false,
  221. DatabaseTypeName: "char",
  222. DatabaseTypePretty: "char(7)",
  223. IsPrimaryKey: false,
  224. IsAutoIncrement: false,
  225. IsArray: false,
  226. ColumnType: "char",
  227. ColumnLength: 7,
  228. GoFieldName: "RequestCurrency",
  229. GoFieldType: "string",
  230. JSONFieldName: "request_currency",
  231. ProtobufFieldName: "request_currency",
  232. ProtobufType: "string",
  233. ProtobufPos: 8,
  234. },
  235. &ColumnInfo{
  236. Index: 8,
  237. Name: "request_balance",
  238. Comment: ``,
  239. Notes: ``,
  240. Nullable: true,
  241. DatabaseTypeName: "double",
  242. DatabaseTypePretty: "double",
  243. IsPrimaryKey: false,
  244. IsAutoIncrement: false,
  245. IsArray: false,
  246. ColumnType: "double",
  247. ColumnLength: -1,
  248. GoFieldName: "RequestBalance",
  249. GoFieldType: "null.Float",
  250. JSONFieldName: "request_balance",
  251. ProtobufFieldName: "request_balance",
  252. ProtobufType: "float",
  253. ProtobufPos: 9,
  254. },
  255. &ColumnInfo{
  256. Index: 9,
  257. Name: "created_at",
  258. Comment: ``,
  259. Notes: ``,
  260. Nullable: false,
  261. DatabaseTypeName: "timestamp",
  262. DatabaseTypePretty: "timestamp",
  263. IsPrimaryKey: false,
  264. IsAutoIncrement: false,
  265. IsArray: false,
  266. ColumnType: "timestamp",
  267. ColumnLength: -1,
  268. GoFieldName: "CreatedAt",
  269. GoFieldType: "time.Time",
  270. JSONFieldName: "created_at",
  271. ProtobufFieldName: "created_at",
  272. ProtobufType: "uint64",
  273. ProtobufPos: 10,
  274. },
  275. &ColumnInfo{
  276. Index: 10,
  277. Name: "updated_at",
  278. Comment: ``,
  279. Notes: ``,
  280. Nullable: false,
  281. DatabaseTypeName: "timestamp",
  282. DatabaseTypePretty: "timestamp",
  283. IsPrimaryKey: false,
  284. IsAutoIncrement: false,
  285. IsArray: false,
  286. ColumnType: "timestamp",
  287. ColumnLength: -1,
  288. GoFieldName: "UpdatedAt",
  289. GoFieldType: "time.Time",
  290. JSONFieldName: "updated_at",
  291. ProtobufFieldName: "updated_at",
  292. ProtobufType: "uint64",
  293. ProtobufPos: 11,
  294. },
  295. &ColumnInfo{
  296. Index: 11,
  297. Name: "deleted_at",
  298. Comment: ``,
  299. Notes: ``,
  300. Nullable: true,
  301. DatabaseTypeName: "timestamp",
  302. DatabaseTypePretty: "timestamp",
  303. IsPrimaryKey: false,
  304. IsAutoIncrement: false,
  305. IsArray: false,
  306. ColumnType: "timestamp",
  307. ColumnLength: -1,
  308. GoFieldName: "DeletedAt",
  309. GoFieldType: "null.Time",
  310. JSONFieldName: "deleted_at",
  311. ProtobufFieldName: "deleted_at",
  312. ProtobufType: "uint64",
  313. ProtobufPos: 12,
  314. },
  315. },
  316. }
  317. // TableName sets the insert table name for this struct type
  318. func (u *UserWallet) TableName() string {
  319. return "user_wallet"
  320. }
  321. // BeforeSave invoked before saving, return an error if field is not populated.
  322. func (u *UserWallet) BeforeSave(*gorm.DB) error {
  323. return nil
  324. }
  325. // Prepare invoked before saving, can be used to populate fields etc.
  326. func (u *UserWallet) Prepare() {
  327. }
  328. // Validate invoked before performing action, return an error if field is not populated.
  329. func (u *UserWallet) Validate(action Action) error {
  330. return nil
  331. }
  332. // TableInfo return table meta data
  333. func (u *UserWallet) TableInfo() *TableInfo {
  334. return user_walletTableInfo
  335. }