diff --git a/.env.example b/.env.example deleted file mode 100644 index 51c2c8d..0000000 --- a/.env.example +++ /dev/null @@ -1,27 +0,0 @@ -# Enviroment -ENVIRONMENT=(dev | prod) - -# Pactus -PACTUS_WALLET_ADDRESS= -PACTUS_WALLET_PASSWORD= -PACTUS_WALLET_PATH= -PACTUS_RPC= - -# Polygon -POLYGON_PRIVATE_KEY= -POLYGON_CONTRACT_ADDRESS= -POLYGON_RPC= - -# Database -DATABASE_DSN= - -# Logger -LOG_LEVEL=info -LOG_FILENAME=wrapto.log -LOG_MAX_SIZE=10 -LOG_MAX_BACKUPS=10 -LOG_COMPRESS=(true | 1 | T) or (false | 0 | F) -LOG_TARGETS=file,console - -# HTTP Server -HTTP_PORT=:3000 diff --git a/README.md b/README.md index ef5b22c..f1d1dd2 100644 --- a/README.md +++ b/README.md @@ -20,19 +20,9 @@ In [PAC Zone](https://github.com/PACZone) (powered by [Dezh](https://dezh.tech)) Currently, Wrapto is a semi-centralized protocol (half decentralized) since there is no contract support on Pactus. [More details about this are here](#Documentation). -#### Our RoadMap - -- [ ] We will add [wPAC](https://github.com/PACZone/wPAC) to More blockchains such as Solana, TON, Aptos, etc. -- [ ] We have a plan to update the protocol and use Pactus contracts (still decentralized and trustless but using contracts) in 2025 Q1 once contracts are available on Pactus (Wrapto Protocol V2). -- [ ] After contract support on the Pactus chain we will add wrapped other coins on Pactus too(Wrapto Protocol V2). - -All V1(semi-centralized)an V2(decentralizes smart-contract) [Wrapped Tokens](https://github.com/PACZone/wPAC) minted on different networks, will be compatible with Wrapto. - # Documentation -## Wrapto Protocol V1 - -You can find all V1 documentations [here](./docs/V1) +You can find all documentations [here](./docs/) # Contribution diff --git a/config/.develop.env b/config/.develop.env new file mode 100644 index 0000000..e6add50 --- /dev/null +++ b/config/.develop.env @@ -0,0 +1,9 @@ +# Pactus +WRAPTO_PACTUS_WALLET_PASSWORD= + +# Polygon +WRAPTO_POLYGON_PRIVATE_KEY= + +# Database +WRAPTO_MONGO_URI= + diff --git a/config/config.go b/config/config.go index 8e543f9..cdda9df 100644 --- a/config/config.go +++ b/config/config.go @@ -2,103 +2,63 @@ package config import ( "os" - "strconv" - "strings" + + "github.com/PACZone/wrapto/database" + logger "github.com/PACZone/wrapto/log" + "github.com/PACZone/wrapto/sides/pactus" + "github.com/PACZone/wrapto/sides/polygon" + "github.com/PACZone/wrapto/www/http" + "github.com/joho/godotenv" + "gopkg.in/yaml.v2" ) type Config struct { - Environment string - Logger LoggerConfig - Pactus PactusConfig - Polygon PolygonConfig - Database DatabaseConfig - HTTPServer HTTPServerConfig -} - -type PactusConfig struct { - WalletPath string - WalletPass string - LockAddr string - RPCNode string -} - -type PolygonConfig struct { - PrivateKey string - ContractAddr string - RPCNode string -} - -type DatabaseConfig struct { - DSN string -} - -type HTTPServerConfig struct { - Port string -} - -type LoggerConfig struct { - Filename string - LogLevel string - Targets []string - MaxSize int - MaxBackups int - Compress bool + Environment string `yaml:"environment"` + Logger logger.Config + Pactus pactus.Config + Polygon polygon.Config + Database database.Config + HTTPServer http.Config } -func LoadConfig() (*Config, error) { - maxSizeStr := os.Getenv("LOG_MAX_SIZE") - maxSize, err := strconv.Atoi(maxSizeStr) +func LoadConfig(path string) (*Config, error) { + file, err := os.Open(path) if err != nil { - return nil, err + return nil, Error{ + reason: err.Error(), + } } + defer file.Close() - maxBackupsStr := os.Getenv("LOG_MAX_BACKUPS") - maxBackups, err := strconv.Atoi(maxBackupsStr) - if err != nil { - return nil, err - } + config := &Config{} - compressStr := os.Getenv("LOG_COMPRESS") - compress, err := strconv.ParseBool(compressStr) - if err != nil { - return nil, err - } + decoder := yaml.NewDecoder(file) - cfg := &Config{ - Environment: os.Getenv("ENVIRONMENT"), - Logger: LoggerConfig{ - Filename: os.ExpandEnv("LOG_FILENAME"), - LogLevel: os.Getenv("LOG_LEVEL"), - Targets: strings.Split(os.Getenv("LOG_TARGETS"), ","), - MaxSize: maxSize, - MaxBackups: maxBackups, - Compress: compress, - }, - Pactus: PactusConfig{ - WalletPath: os.Getenv("PACTUS_WALLET_PATH"), - WalletPass: os.Getenv("PACTUS_WALLET_PASSWORD"), - LockAddr: os.Getenv("PACTUS_WALLET_ADDRESS"), - RPCNode: os.Getenv("PACTUS_RPC"), - }, - Polygon: PolygonConfig{ - PrivateKey: os.Getenv("POLYGON_PRIVATE_KEY"), - ContractAddr: os.Getenv("POLYGON_CONTRACT_ADDRESS"), - RPCNode: os.Getenv("POLYGON_RPC"), - }, - Database: DatabaseConfig{ - os.Getenv("DATABASE_DSN"), - }, + if err := decoder.Decode(config); err != nil { + return nil, Error{ + reason: err.Error(), + } + } - HTTPServer: HTTPServerConfig{ - Port: os.Getenv("HTTP_PORT"), - }, + if config.Environment != "prod" { + if err := godotenv.Load(); err != nil { + return nil, Error{ + reason: err.Error(), + } + } } - if err := cfg.basicCheck(); err != nil { - return nil, err + config.Database.URI = os.Getenv("WRAPTO_MONGO_URI") + config.Pactus.WalletPass = os.Getenv("WRAPTO_PACTUS_WALLET_PASSWORD") + config.Polygon.PrivateKey = os.Getenv("WRAPTO_POLYGON_PRIVATE_KEY") + + if err = config.basicCheck(); err != nil { + return nil, Error{ + reason: err.Error(), + } } - return cfg, nil + return config, nil } func (c *Config) basicCheck() error { diff --git a/config/config.yml b/config/config.yml new file mode 100644 index 0000000..65304c2 --- /dev/null +++ b/config/config.yml @@ -0,0 +1,28 @@ +environment: dev # or prod. + +logger: + file_name: wrapto.log + log_level: info + targets: + - console + - file + max_size: 100 + max_backups: 10 + compress: true + +pactus: + wallet_path: /path/to/wallet + lock_address: pc1zgp0x33hehvczq6dggs04gywfqpzl9fea5039gh + rpc_url: https://rpc.pactus.example.com + +polygon: + contract_address: 0x2f77E0afAEE06970Bf860B8267b5aFECFFF6F216 + rpc_url: https://rpc.polygon.example.com + +database: + db_name: wrapto + connection_timeout_in_ms: 5000 + query_timeout_in_ms: 3000 + +http: + port: ":8080" \ No newline at end of file diff --git a/config/erros.go b/config/erros.go index e99f385..69f27ce 100644 --- a/config/erros.go +++ b/config/erros.go @@ -9,3 +9,12 @@ type InvalidEnvironmentError struct { func (e InvalidEnvironmentError) Error() string { return fmt.Sprintf("environment can be `dev` or `prod` not: %s", e.Environment) } + +// Error represents an error in loading or validating config. +type Error struct { + reason string +} + +func (e Error) Error() string { + return fmt.Sprintf("config error: %s\n", e.reason) +} diff --git a/core/core.go b/core/core.go index 68326a0..c783ba3 100644 --- a/core/core.go +++ b/core/core.go @@ -14,8 +14,8 @@ type Core struct { mgr *manager.Manager } -func NewCore(ctx context.Context, cancel context.CancelFunc) (*Core, error) { - cfg, err := config.LoadConfig() +func NewCore(ctx context.Context, cancel context.CancelFunc, path string) (*Core, error) { + cfg, err := config.LoadConfig(path) if err != nil { cancel() @@ -24,7 +24,7 @@ func NewCore(ctx context.Context, cancel context.CancelFunc) (*Core, error) { logger.InitGlobalLogger(&cfg.Logger) - db, err := database.NewDB(cfg.Database.DSN) + db, err := database.Connect(cfg.Database) //nolint if err != nil { cancel() diff --git a/database/config.go b/database/config.go new file mode 100644 index 0000000..0959162 --- /dev/null +++ b/database/config.go @@ -0,0 +1,8 @@ +package database + +type Config struct { + URI string + DBName string `yaml:"db_name"` + ConnectionTimeout int16 `yaml:"connection_timeout_in_ms"` + QueryTimeout int16 `yaml:"query_timeout_in_ms"` +} diff --git a/database/database.go b/database/database.go index d31ee1a..f4a8940 100644 --- a/database/database.go +++ b/database/database.go @@ -1,231 +1,96 @@ package database import ( - "errors" + "context" + "time" "github.com/PACZone/wrapto/types/order" - "gorm.io/driver/postgres" - "gorm.io/gorm" - "gorm.io/gorm/logger" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" ) -type DB struct { - *gorm.DB +type Database struct { + DBName string + QueryTimeout time.Duration + Client *mongo.Client } -func NewDB(dsn string) (*DB, error) { - db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{ - Logger: logger.Default.LogMode(logger.Error), - }) +func Connect(cfg Config) (*Database, error) { + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(cfg.ConnectionTimeout)*time.Millisecond) + defer cancel() + + serverAPI := options.ServerAPI(options.ServerAPIVersion1) + opts := options.Client().ApplyURI(cfg.URI). + SetServerAPIOptions(serverAPI). + SetConnectTimeout(time.Duration(cfg.ConnectionTimeout) * time.Millisecond). + SetBSONOptions(&options.BSONOptions{ + UseJSONStructTags: true, + NilSliceAsEmpty: true, + }) + + client, err := mongo.Connect(ctx, opts) if err != nil { - return nil, DBError{ - Reason: err.Error(), - } + return nil, err } - if !db.Migrator().HasTable(&Order{}) || !db.Migrator().HasTable(&Log{}) || !db.Migrator().HasTable(&State{}) { - if err := db.AutoMigrate( - &Order{}, - &Log{}, - &State{}, - ); err != nil { - return nil, DBError{ - Reason: err.Error(), - } - } - - defaultState := &State{ - Pactus: 638364, - Polygon: 1, - } - if err := db.Create(defaultState).Error; err != nil { - return nil, DBError{ - TableName: "State", - Reason: err.Error(), - } - } + qCtx, cancel := context.WithTimeout(context.Background(), time.Duration(cfg.QueryTimeout)*time.Millisecond) + defer cancel() + + if err := client.Ping(qCtx, nil); err != nil { + return nil, err } - return &DB{ - DB: db, + return &Database{ + Client: client, + DBName: cfg.DBName, + QueryTimeout: time.Duration(cfg.QueryTimeout) * time.Millisecond, }, nil } -func (db *DB) AddOrder(ord *order.Order) (string, error) { - o := &Order{ - ID: ord.ID, - TxHash: ord.TxHash, - Receiver: ord.Receiver, - Sender: ord.Sender, - Amount: ord.OriginalAmount(), - Fee: ord.Fee(), - Status: ord.Status, - BridgeType: ord.BridgeType, - } - if err := db.Create(o).Error; err != nil { - return "", DBError{ - TableName: "Orders", - Reason: err.Error(), - } - } - - return ord.ID, nil +func (db *Database) AddOrder(_ *order.Order) (string, error) { + return "", nil } -func (db *DB) AddLog(orderID, actor, desc, trace string) error { - log := &Log{ - OrderID: orderID, - Actor: actor, - Description: desc, - Trace: trace, - } - - if err := db.Create(log).Error; err != nil { - return DBError{ - TableName: "Logs", - Reason: err.Error(), - } - } - +func (db *Database) AddLog(_, _, _, _ string) error { return nil } -func (db *DB) UpdateOrderStatus(id string, status order.Status) error { - if err := db.Model(&Order{}).Where("id = ?", id).Update("status", status).Error; err != nil { - return DBError{ - TableName: "Orders", - Reason: err.Error(), - } - } - +func (db *Database) UpdateOrderStatus(_ string, _ order.Status) error { return nil } -func (db *DB) UpdateOrderDestTxHash(id, hash string) error { - if err := db.Model(&Order{}).Where("id = ?", id).Update("dest_network_tx_hash", hash).Error; err != nil { - return DBError{ - TableName: "Orders", - Reason: err.Error(), - } - } - +func (db *Database) UpdateOrderDestTxHash(_, _ string) error { return nil } -func (db *DB) UpdateOrderReason(id, reason string) error { - if err := db.Model(&Order{}).Where("id = ?", id).Update("reason", reason).Error; err != nil { - return DBError{ - TableName: "Orders", - Reason: err.Error(), - } - } - +func (db *Database) UpdateOrderReason(_, _ string) error { return nil } -func (db *DB) GetOrder(id string) (*Order, error) { - var ord *Order - if err := db.First(&ord, "id = ?", id).Error; err != nil { - return nil, DBError{ - TableName: "Orders", - Reason: err.Error(), - } - } - - return ord, nil +func (db *Database) GetOrder(_ string) (*order.Order, error) { + return nil, nil //nolint } -func (db *DB) IsOrderExist(txHash string) (bool, error) { - var ord Order - err := db.Where("tx_hash = ?", txHash).First(&ord).Error - if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { - return false, nil - } else if err != nil { - return false, DBError{ - TableName: "Orders", - Reason: err.Error(), - } - } - - return true, nil +func (db *Database) IsOrderExist(_ string) (bool, error) { + return false, nil } -func (db *DB) GetOrderWithLogs(id string) (*Order, error) { - var ord *Order - if err := db.Preload("Logs").First(&ord, "id = ?", id).Error; err != nil { - return nil, DBError{ - TableName: "Orders", - Reason: err.Error(), - } - } - - return ord, nil -} - -func (db *DB) GetOrderLogs(orderID string) ([]Log, error) { - var logs []Log - if err := db.Where("order_id = ?", orderID).Find(&logs).Error; err != nil { - return nil, DBError{ - TableName: "Logs", - Reason: err.Error(), - } - } - - return logs, nil -} - -func (db *DB) UpdatePactusState(pactus uint32) error { - var state State - if err := db.First(&state).Error; err != nil { - return err - } - - state.Pactus = pactus - - return db.Save(&state).Error +func (db *Database) UpdatePactusState(_ uint32) error { + return nil } -func (db *DB) UpdatePolygonState(polygon uint32) error { - var state State - if err := db.First(&state).Error; err != nil { - return err - } - - state.Polygon = polygon - - return db.Save(&state).Error +func (db *Database) UpdatePolygonState(_ uint32) error { + return nil } -func (db *DB) GetState() (*State, error) { - var state State - if err := db.First(&state).Error; err != nil { - return nil, err - } - - return &state, nil +func (db *Database) GetState() (*State, error) { + return nil, nil //nolint } -func (db *DB) GetLatestOrders(limit int) ([]*Order, error) { - var orders []*Order - if err := db.Order("created_at desc").Limit(limit).Find(&orders).Error; err != nil { - return nil, DBError{ - TableName: "Orders", - Reason: err.Error(), - } - } - - return orders, nil +func (db *Database) GetLatestOrders(_ int) ([]*order.Order, error) { + return nil, nil } -func (db *DB) SearchOrders(q string) ([]*Order, error) { - var orders []*Order - if err := db.Where("tx_hash = ? OR receiver = ? OR sender = ? OR dest_network_tx_hash = ?", - q, q, q, q).Find(&orders).Error; err != nil { - return nil, DBError{ - TableName: "Orders", - Reason: err.Error(), - } - } - - return orders, nil +func (db *Database) SearchOrders(_ string) ([]*order.Order, error) { + return nil, nil } diff --git a/database/database_test.go b/database/database_test.go deleted file mode 100644 index 4a6cbf3..0000000 --- a/database/database_test.go +++ /dev/null @@ -1,248 +0,0 @@ -package database_test - -// import ( -// "fmt" -// "os" -// "testing" - -// "github.com/PACZone/wrapto/database" -// "github.com/PACZone/wrapto/types/order" -// "github.com/stretchr/testify/assert" -// "github.com/stretchr/testify/require" -// "gorm.io/gorm" -// ) - -// func setup(t *testing.T) *database.DB { -// t.Helper() - -// file, err := os.CreateTemp("", "temp-db") -// require.NoError(t, err) - -// db, err := database.NewDB(file.Name()) -// require.NoError(t, err) - -// return db -// } - -// func TestAddOrder(t *testing.T) { -// db := setup(t) - -// ord, err := order.NewOrder("aaa", "sendet", "rec", 20e9) -// assert.NoError(t, err) - -// ordID, err := db.AddOrder(ord) -// assert.NoError(t, err) - -// assert.Equal(t, ord.ID, ordID) -// } - -// func TestAddLog(t *testing.T) { -// db := setup(t) - -// err := db.AddLog("1", "POLYGON", "this is test desc", "trace") -// assert.NoError(t, err) -// } - -// func TestAddLogForOrder(t *testing.T) { -// db := setup(t) - -// ord, err := order.NewOrder("aaa", "sendet", "rec", 20e9) -// assert.NoError(t, err) - -// ordID, err := db.AddOrder(ord) -// assert.NoError(t, err) - -// err = db.AddLog(ordID, "POLYGON", "desc", "trace") -// assert.NoError(t, err) -// } - -// func TestUpdateOrderStatus(t *testing.T) { -// db := setup(t) - -// ord, err := order.NewOrder("0xFFFF", "sender", "receiver", 2e9) -// require.NoError(t, err) - -// ordID, err := db.AddOrder(ord) -// require.NoError(t, err) - -// err = db.UpdateOrderStatus(ordID, order.COMPLETE) -// require.NoError(t, err) - -// updatedOrd, err := db.GetOrder(ordID) -// require.NoError(t, err) - -// assert.Equal(t, order.COMPLETE, updatedOrd.Status) -// } - -// func TestGetOrder(t *testing.T) { -// db := setup(t) - -// ord, err := order.NewOrder("aaa", "sendet", "rec", 20e9) -// require.NoError(t, err) - -// ordID, err := db.AddOrder(ord) -// require.NoError(t, err) - -// retrievedOrd, err := db.GetOrder(ordID) -// require.NoError(t, err) -// assert.Equal(t, retrievedOrd.ID, ord.ID) -// assert.Equal(t, retrievedOrd.TxHash, ord.TxHash) -// assert.Equal(t, retrievedOrd.Amount, ord.OriginalAmount()) -// assert.Equal(t, retrievedOrd.Fee, ord.Fee()) -// assert.Equal(t, retrievedOrd.Sender, ord.Sender) -// assert.Equal(t, retrievedOrd.Receiver, ord.Receiver) -// } - -// func TestGetOrderWithLogs(t *testing.T) { -// db := setup(t) - -// ord, err := order.NewOrder("aaa", "sendet", "rec", 20e9) -// assert.NoError(t, err) - -// ordID, err := db.AddOrder(ord) -// assert.NoError(t, err) - -// err = db.AddLog(ordID, "POLYGON", "descriptivjerijw", "trace") - -// assert.NoError(t, err) - -// ordWithLogs, err := db.GetOrderWithLogs(ordID) -// assert.NoError(t, err) - -// assert.Equal(t, len(ordWithLogs.Logs), 1) -// } - -// func TestGetOrderLogs(t *testing.T) { -// db := setup(t) - -// ord, err := order.NewOrder("aaa", "sendet", "rec", 20e9) -// assert.NoError(t, err) - -// ordID, err := db.AddOrder(ord) -// assert.NoError(t, err) - -// err = db.AddLog(ordID, "POLYGON", "abcd", "traceAbcd") - -// assert.NoError(t, err) - -// logs, err := db.GetOrderLogs(ordID) -// assert.NoError(t, err) - -// l := logs[0] -// assert.Equal(t, l.Actor, "POLYGON") -// assert.Equal(t, l.Description, "abcd") -// assert.Equal(t, l.Trace, "traceAbcd") -// assert.Equal(t, l.OrderID, ordID) -// } - -// func TestIsOrderExist(t *testing.T) { -// db := setup(t) - -// ord, err := order.NewOrder("aaa", "sendet", "rec", 20e9) -// assert.NoError(t, err) - -// ordID, err := db.AddOrder(ord) -// assert.NoError(t, err) - -// isExist, err := db.IsOrderExist("bbb") -// assert.Equal(t, isExist, false) -// assert.Error(t, gorm.ErrRecordNotFound, err) - -// isExist, err = db.IsOrderExist("aaa") -// assert.Equal(t, isExist, true) -// assert.NoError(t, err) - -// assert.Equal(t, ord.ID, ordID) -// } - -// func TestUpdatePactusState(t *testing.T) { -// db := setup(t) - -// state := database.State{ -// Pactus: 0, -// Polygon: 0, -// } -// assert.NoError(t, db.Create(&state).Error) - -// err := db.UpdatePactusState(42) -// assert.NoError(t, err) - -// var updatedState database.State -// assert.NoError(t, db.First(&updatedState).Error) -// assert.Equal(t, uint32(42), updatedState.Pactus) -// } - -// func TestUpdatePolygonState(t *testing.T) { -// db := setup(t) - -// state := database.State{ -// Pactus: 0, -// Polygon: 0, -// } -// assert.NoError(t, db.Create(&state).Error) - -// err := db.UpdatePolygonState(100) -// assert.NoError(t, err) - -// var updatedState database.State -// assert.NoError(t, db.First(&updatedState).Error) -// assert.Equal(t, uint32(100), updatedState.Polygon) -// } - -// func TestGetState(t *testing.T) { -// db := setup(t) - -// err := db.UpdatePolygonState(100) -// assert.NoError(t, err) - -// err = db.UpdatePactusState(42) -// assert.NoError(t, err) - -// retrievedState, err := db.GetState() -// assert.NoError(t, err) -// assert.Equal(t, uint32(42), retrievedState.Pactus) -// assert.Equal(t, uint32(100), retrievedState.Polygon) -// } - -// func TestGetLatestOrders(t *testing.T) { -// db := setup(t) - -// for i := 0; i < 15; i++ { -// ord, err := order.NewOrder(fmt.Sprintf("tx%d", i), fmt.Sprintf("sender%d", i), fmt.Sprintf("receiver%d", i), 20e9) -// require.NoError(t, err) -// _, err = db.AddOrder(ord) -// require.NoError(t, err) -// } - -// orders, err := db.GetLatestOrders(10) -// require.NoError(t, err) - -// require.Len(t, orders, 10) - -// for i := 0; i < 10; i++ { -// assert.Equal(t, fmt.Sprintf("tx%d", 14-i), orders[i].TxHash) -// } -// } - -// func TestSearchOrders(t *testing.T) { -// db := setup(t) - -// for i := 0; i < 5; i++ { -// ord, err := order.NewOrder(fmt.Sprintf("tx%d", i), fmt.Sprintf("sender%d", i), fmt.Sprintf("receiver%d", i), 20e9) -// require.NoError(t, err) -// _, err = db.AddOrder(ord) -// require.NoError(t, err) -// } - -// orders, err := db.SearchOrders("tx2") -// require.NoError(t, err) - -// require.Len(t, orders, 1) -// assert.Equal(t, "tx2", orders[0].TxHash) - -// orders, err = db.SearchOrders("receiver3") -// require.NoError(t, err) - -// require.Len(t, orders, 1) -// assert.Equal(t, "receiver3", orders[0].Receiver) -// } diff --git a/database/models.go b/database/models.go index 4b9df34..e9ed7a6 100644 --- a/database/models.go +++ b/database/models.go @@ -1,66 +1,17 @@ package database -import ( - "time" - - "github.com/PACZone/wrapto/types/order" - "github.com/pactus-project/pactus/types/amount" - "gorm.io/gorm" -) - -type Order struct { - // * unique ID on wrapto system. - ID string `gorm:"primaryKey"` - - // * transaction or contract call that user made on source network. - TxHash string - - // * address of receiver account on destination network. - Receiver string - - // * address of sender on source network (account that made bridge transaction). - Sender string - - // * amount of PAC to be bridged, **including fee**. - Amount amount.Amount - - // * fee of order on wrapto system - Fee amount.Amount - - // * status of order on wrapto system. - Status order.Status - - // * once status got COMPLETE, this will be filled with destination network transaction hash made by wrapto. - DestNetworkTxHash string - - // * will be filled if order failed. - Reason string - - BridgeType order.BridgeType - - CreatedAt time.Time `gorm:"autoCreateTime"` - - Logs []Log `gorm:"foreignKey:OrderID"` - - gorm.Model -} - type Log struct { - Actor string + Actor string `bson:"actor"` - Description string + Description string `bson:"description"` - Trace string + Trace string `bson:"trace"` - OrderID string - - gorm.Model + OrderID string `bson:"order_id"` } type State struct { - Pactus uint32 - - Polygon uint32 + Pactus uint32 `bson:"pactus"` - gorm.Model + Polygon uint32 `bson:"polygon"` } diff --git a/docs/V1/design.md b/docs/design.md similarity index 100% rename from docs/V1/design.md rename to docs/design.md diff --git a/docs/V1/protocol(standard).md b/docs/protocol(standard).md similarity index 100% rename from docs/V1/protocol(standard).md rename to docs/protocol(standard).md diff --git a/docs/V1/user.md b/docs/user.md similarity index 100% rename from docs/V1/user.md rename to docs/user.md diff --git a/go.mod b/go.mod index b707821..29989c0 100644 --- a/go.mod +++ b/go.mod @@ -6,13 +6,15 @@ toolchain go1.22.5 require ( github.com/ethereum/go-ethereum v1.14.8 + github.com/joho/godotenv v1.5.1 github.com/labstack/echo/v4 v4.12.0 github.com/pactus-project/pactus v1.4.0 github.com/rs/zerolog v1.33.0 github.com/stretchr/testify v1.9.0 + go.mongodb.org/mongo-driver v1.17.1 google.golang.org/grpc v1.65.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 - gorm.io/driver/postgres v1.5.9 + gopkg.in/yaml.v2 v2.4.0 ) require ( @@ -31,25 +33,22 @@ require ( github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect + github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect github.com/holiman/uint256 v1.3.1 // indirect github.com/iancoleman/strcase v0.3.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect - github.com/jackc/pgx/v5 v5.6.0 // indirect - github.com/jackc/puddle/v2 v2.2.1 // indirect - github.com/jinzhu/inflection v1.0.0 // indirect - github.com/jinzhu/now v1.1.5 // indirect github.com/kilic/bls12-381 v0.1.0 // indirect + github.com/klauspost/compress v1.17.9 // indirect github.com/labstack/gommon v0.4.2 // indirect github.com/matoous/go-nanoid v1.5.0 github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect + github.com/montanaflynn/stats v0.7.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect github.com/spf13/cast v1.7.0 // indirect @@ -62,6 +61,10 @@ require ( github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect github.com/x448/float16 v0.8.4 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect golang.org/x/crypto v0.26.0 // indirect golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 // indirect @@ -74,6 +77,5 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20240823204242-4ba0660f739c // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - gorm.io/gorm v1.25.11 rsc.io/tmplfunc v0.0.3 // indirect ) diff --git a/go.sum b/go.sum index 59f9060..6892626 100644 --- a/go.sum +++ b/go.sum @@ -48,7 +48,6 @@ github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c h1:uQYC5Z1mdLR github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v1.1.0 h1:EN/u9k2TF6OWSHrCCDBBU6GLNMq88OspHHlMnHfoyU4= github.com/crate-crypto/go-kzg-4844 v1.1.0/go.mod h1:JolLjpSff1tCCJKaJx4psrlEdlXuJEC996PL3tTAFks= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= @@ -156,24 +155,14 @@ github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= github.com/ipld/go-ipld-prime v0.21.0 h1:n4JmcpOlPDIxBcY037SVfpd1G+Sj1nKZah0m6QH9C2E= github.com/ipld/go-ipld-prime v0.21.0/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOanyMctpPjsvxQ= -github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= -github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= -github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= -github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= -github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= -github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-temp-err-catcher v0.1.0 h1:zpb3ZH6wIE8Shj2sKS+khgRvf7T7RABoLk/+KKHggpk= github.com/jbenet/go-temp-err-catcher v0.1.0/go.mod h1:0kJRvmDZXNMIiJirNPEYfhpPwbGVtZVWC34vc5WLsDk= github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o= github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= -github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= -github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= -github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/kilic/bls12-381 v0.1.0 h1:encrdjqKMEvabVQ7qYOKu1OvhqpK4s47wDYtNiPtlp4= github.com/kilic/bls12-381 v0.1.0/go.mod h1:vDTTHJONJ6G+P2R74EhnyotQDTliQDnFEwhdmfzw1ig= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= @@ -253,6 +242,8 @@ github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8oh github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= +github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= +github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= @@ -366,9 +357,6 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/supranational/blst v0.3.13 h1:AYeSxdOMacwu7FBmpfloBz5pbFXDmJL33RuwnKtmTjk= @@ -391,10 +379,21 @@ github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdz github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM= +go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= @@ -415,34 +414,54 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA= golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201101102859-da207088b7d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.15.0 h1:2lYxjRbTYyxkJxlhC+LvJIx3SsANPdRybu1tGj9/OrQ= gonum.org/v1/gonum v0.15.0/go.mod h1:xzZVBJBtS+Mz4q0Yl2LJTk+OxOg4jiXZ7qBoM0uISGo= google.golang.org/genproto/googleapis/api v0.0.0-20240823204242-4ba0660f739c h1:e0zB268kOca6FbuJkYUGxfwG4DKFZG/8DLyv9Zv66cE= @@ -460,13 +479,8 @@ gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8= -gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= -gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= -gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= lukechampine.com/blake3 v1.3.0 h1:sJ3XhFINmHSrYCgl958hscfIa3bw8x4DqMP3u1YvoYE= lukechampine.com/blake3 v1.3.0/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= diff --git a/log/config.go b/log/config.go new file mode 100644 index 0000000..b1e0efd --- /dev/null +++ b/log/config.go @@ -0,0 +1,10 @@ +package logger + +type Config struct { + Filename string `yaml:"file_name"` + LogLevel string `yaml:"log_level"` + Targets []string `yaml:"targets"` + MaxSize int `yaml:"max_size"` + MaxBackups int `yaml:"max_backups"` + Compress bool `yaml:"compress"` +} diff --git a/log/logger.go b/log/logger.go index 8854a24..e20d0b1 100644 --- a/log/logger.go +++ b/log/logger.go @@ -9,7 +9,6 @@ import ( "slices" "strings" - "github.com/PACZone/wrapto/config" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "gopkg.in/natefinch/lumberjack.v2" @@ -21,7 +20,7 @@ type logger struct { writer io.Writer } -func InitGlobalLogger(cfg *config.LoggerConfig) { +func InitGlobalLogger(cfg *Config) { if globalInst == nil { var writers []io.Writer diff --git a/main.go b/main.go index 98cd43a..96bac7e 100644 --- a/main.go +++ b/main.go @@ -12,9 +12,9 @@ import ( "github.com/spf13/cobra" ) -func run(cmd *cobra.Command, _ []string) { +func run(cmd *cobra.Command, args []string) { ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, os.Interrupt) - c, err := core.NewCore(ctx, cancel) + c, err := core.NewCore(ctx, cancel, args[0]) exitOnError(cmd, err) go c.Start() diff --git a/manager/manager.go b/manager/manager.go index 745805e..e408bac 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -29,7 +29,9 @@ type actors struct { http *http.Server } -func NewManager(ctx context.Context, cancel context.CancelFunc, cfg *config.Config, db *database.DB) (*Manager, error) { +func NewManager(ctx context.Context, cancel context.CancelFunc, + cfg *config.Config, db *database.Database, +) (*Manager, error) { highway := make(chan message.Message, 10) // TODO: what should we use as size? bypasses := make(map[bypass.Name]chan message.Message, 10) // TODO: what should we use as size? diff --git a/sides/pactus/bridge.go b/sides/pactus/bridge.go index af8aa26..fc603e1 100644 --- a/sides/pactus/bridge.go +++ b/sides/pactus/bridge.go @@ -13,14 +13,14 @@ import ( type Bridge struct { wallet *Wallet - db *database.DB + db *database.Database bypassName bypass.Name bypass chan message.Message ctx context.Context } -func newBridge(ctx context.Context, w *Wallet, b chan message.Message, bn bypass.Name, db *database.DB) Bridge { +func newBridge(ctx context.Context, w *Wallet, b chan message.Message, bn bypass.Name, db *database.Database) Bridge { return Bridge{ wallet: w, bypass: b, diff --git a/sides/pactus/config.go b/sides/pactus/config.go new file mode 100644 index 0000000..73a9555 --- /dev/null +++ b/sides/pactus/config.go @@ -0,0 +1,8 @@ +package pactus + +type Config struct { + WalletPath string `yaml:"wallet_path"` + WalletPass string + LockAddr string `yaml:"lock_address"` + RPCNode string `yaml:"rpc_url"` +} diff --git a/sides/pactus/listener.go b/sides/pactus/listener.go index 5458c23..21e876e 100644 --- a/sides/pactus/listener.go +++ b/sides/pactus/listener.go @@ -17,7 +17,7 @@ import ( type Listener struct { client *Client - db *database.DB + db *database.Database nextBlockNumber uint32 bypassName bypass.Name highway chan message.Message @@ -29,7 +29,7 @@ type Listener struct { func newListener(ctx context.Context, client *Client, bp bypass.Name, highway chan message.Message, startBlock uint32, lockAddr string, - db *database.DB, + db *database.Database, ) *Listener { return &Listener{ client: client, diff --git a/sides/pactus/pactus.go b/sides/pactus/pactus.go index 9f2fd9a..1ec00fd 100644 --- a/sides/pactus/pactus.go +++ b/sides/pactus/pactus.go @@ -4,7 +4,6 @@ import ( "context" "sync" - "github.com/PACZone/wrapto/config" "github.com/PACZone/wrapto/database" logger "github.com/PACZone/wrapto/log" "github.com/PACZone/wrapto/types/bypass" @@ -23,8 +22,8 @@ type Side struct { func NewSide(ctx context.Context, highway chan message.Message, startBlock uint32, - bp chan message.Message, env string, cfg config.PactusConfig, - db *database.DB, + bp chan message.Message, env string, cfg Config, + db *database.Database, ) (*Side, error) { if env == "dev" { crypto.AddressHRP = "tpc" // TODO: FIX ME!!!!! diff --git a/sides/polygon/bridge.go b/sides/polygon/bridge.go index fb18fdb..1abd091 100644 --- a/sides/polygon/bridge.go +++ b/sides/polygon/bridge.go @@ -15,7 +15,7 @@ import ( type Bridge struct { client *Client - db *database.DB + db *database.Database bypassName bypass.Name bypass chan message.Message @@ -23,7 +23,7 @@ type Bridge struct { } func newBridge(ctx context.Context, bp chan message.Message, - bn bypass.Name, client *Client, db *database.DB, + bn bypass.Name, client *Client, db *database.Database, ) Bridge { return Bridge{ bypass: bp, diff --git a/sides/polygon/config.go b/sides/polygon/config.go new file mode 100644 index 0000000..9a48472 --- /dev/null +++ b/sides/polygon/config.go @@ -0,0 +1,7 @@ +package polygon + +type Config struct { + PrivateKey string + ContractAddr string `yaml:"contract_address"` + RPCNode string `yaml:"rpc_url"` +} diff --git a/sides/polygon/listener.go b/sides/polygon/listener.go index acc185d..d73b41e 100644 --- a/sides/polygon/listener.go +++ b/sides/polygon/listener.go @@ -19,7 +19,7 @@ import ( type Listener struct { client *Client - db *database.DB + db *database.Database bypassName bypass.Name nextOrderNumber uint32 highway chan message.Message @@ -28,7 +28,7 @@ type Listener struct { } func newListener(ctx context.Context, - client *Client, bp bypass.Name, highway chan message.Message, startOrder uint32, db *database.DB, + client *Client, bp bypass.Name, highway chan message.Message, startOrder uint32, db *database.Database, ) *Listener { return &Listener{ client: client, diff --git a/sides/polygon/polygon.go b/sides/polygon/polygon.go index 471742f..4f0166b 100644 --- a/sides/polygon/polygon.go +++ b/sides/polygon/polygon.go @@ -4,7 +4,6 @@ import ( "context" "sync" - "github.com/PACZone/wrapto/config" "github.com/PACZone/wrapto/database" logger "github.com/PACZone/wrapto/log" "github.com/PACZone/wrapto/types/bypass" @@ -20,7 +19,7 @@ type Side struct { client *Client listener *Listener bridge Bridge - db *database.DB + db *database.Database highway chan message.Message bypass chan message.Message @@ -28,7 +27,7 @@ type Side struct { } func NewSide(ctx context.Context, highway chan message.Message, startOrder uint32, - bp chan message.Message, env string, cfg config.PolygonConfig, db *database.DB, + bp chan message.Message, env string, cfg Config, db *database.Database, ) (*Side, error) { chainID := mainChainID if env == "dev" { diff --git a/types/order/order.go b/types/order/order.go index 68a7717..cb2e31d 100644 --- a/types/order/order.go +++ b/types/order/order.go @@ -2,6 +2,7 @@ package order import ( "fmt" + "time" "github.com/PACZone/wrapto/types/params" gonanoid "github.com/matoous/go-nanoid" @@ -25,25 +26,28 @@ const ( type Order struct { // * unique ID on Wrapto system. - ID string + ID string `bson:"id"` // * transaction or contract call that user made on source network. - TxHash string + TxHash string `bson:"tx_hash"` // * address of receiver account on destination network. - Receiver string + Receiver string `bson:"receiver"` // * address of sender on source network (account that made bridge transaction). - Sender string + Sender string `bson:"sender"` // * amount of PAC to be bridged, **including fee**. - amount amount.Amount + amount amount.Amount `bson:"amount"` + + // * amount of PAC to be bridged, **including fee**. + CreatedAt time.Time `bson:"created_at"` // * status of order on Wrapto system. - Status Status + Status Status `bson:"status"` // * type of bridge. - BridgeType BridgeType + BridgeType BridgeType `bson:"bridge_type"` } func NewOrder(txHash, sender, receiver string, amt amount.Amount, t BridgeType) (*Order, error) { diff --git a/www/http/config.go b/www/http/config.go new file mode 100644 index 0000000..d689bd4 --- /dev/null +++ b/www/http/config.go @@ -0,0 +1,5 @@ +package http + +type Config struct { + Port string `yaml:"port"` +} diff --git a/www/http/http.go b/www/http/http.go index abf3b10..d9db777 100644 --- a/www/http/http.go +++ b/www/http/http.go @@ -6,7 +6,6 @@ import ( "strings" "time" - "github.com/PACZone/wrapto/config" "github.com/PACZone/wrapto/database" "github.com/PACZone/wrapto/types/bypass" "github.com/PACZone/wrapto/types/message" @@ -17,9 +16,9 @@ import ( type Server struct { echo *echo.Echo - db *database.DB + db *database.Database ctx context.Context - cfg config.HTTPServerConfig + cfg Config highway chan message.Message } @@ -50,7 +49,7 @@ type RecentTxsResponse struct { Reason string `json:"reason"` } -func NewHTTP(ctx context.Context, cfg config.HTTPServerConfig, db *database.DB, highway chan message.Message) *Server { +func NewHTTP(ctx context.Context, cfg Config, db *database.Database, highway chan message.Message) *Server { app := echo.New() return &Server{ @@ -126,15 +125,15 @@ func (h *Server) recentTxs(c echo.Context) error { for _, tx := range txs { a := RecentTxsResponse{ - From: tx.Receiver, - To: tx.Sender, - Fee: tx.Fee.ToPAC(), - Date: tx.CreatedAt, - Status: tx.Status, - TxID: tx.DestNetworkTxHash, - Amount: tx.Amount.ToPAC(), + From: tx.Receiver, + To: tx.Sender, + Fee: tx.Fee().ToPAC(), + Date: tx.CreatedAt, + Status: tx.Status, + // TxID: tx.DestNetworkTxHash, + Amount: tx.Amount().ToPAC(), BridgeType: string(tx.BridgeType), - Reason: tx.Reason, + // Reason: tx.Reason, } dto = append(dto, a) } @@ -187,15 +186,15 @@ func (h *Server) searchTx(c echo.Context) error { for _, tx := range txs { a := RecentTxsResponse{ - From: tx.Receiver, - To: tx.Sender, - Fee: tx.Fee.ToPAC(), - Date: tx.CreatedAt, - Status: tx.Status, - TxID: tx.DestNetworkTxHash, - Amount: tx.Amount.ToPAC(), + From: tx.Receiver, + To: tx.Sender, + Fee: tx.Fee().ToPAC(), + Date: tx.CreatedAt, + Status: tx.Status, + // TxID: tx.DestNetworkTxHash, + Amount: tx.Amount().ToPAC(), BridgeType: string(tx.BridgeType), - Reason: tx.Reason, + // Reason: tx.Reason, } dto = append(dto, a) }