diff --git a/api/swagger.json b/api/swagger.json index c6b4bd9d..0ee1a506 100644 --- a/api/swagger.json +++ b/api/swagger.json @@ -2595,9 +2595,9 @@ "minimum": 0, "x-go-type": { "import": { - "package": "math/big" + "package": "github.com/aeternity/aepp-sdk-go/utils" }, - "type": "Int" + "type": "BigInt" } }, "Balance": { @@ -2605,9 +2605,9 @@ "minimum": 0, "x-go-type": { "import": { - "package": "math/big" + "package": "github.com/aeternity/aepp-sdk-go/utils" }, - "type": "Int" + "type": "BigInt" } }, "EncodedHash": { @@ -2618,9 +2618,9 @@ "minimum": 0, "x-go-type": { "import": { - "package": "math/big" + "package": "github.com/aeternity/aepp-sdk-go/utils" }, - "type": "Int" + "type": "BigInt" } }, "Pow": { diff --git a/generated/models/account.go b/generated/models/account.go index 368cfd2f..7afe4309 100644 --- a/generated/models/account.go +++ b/generated/models/account.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // Account account @@ -21,7 +21,7 @@ type Account struct { // Balance // Required: true - Balance big.Int `json:"balance"` + Balance utils.BigInt `json:"balance"` // Public key // Required: true diff --git a/generated/models/channel.go b/generated/models/channel.go index a30f776d..4a655c39 100644 --- a/generated/models/channel.go +++ b/generated/models/channel.go @@ -14,7 +14,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // Channel channel @@ -23,11 +23,11 @@ type Channel struct { // channel amount // Required: true - ChannelAmount big.Int `json:"channel_amount"` + ChannelAmount utils.BigInt `json:"channel_amount"` // channel reserve // Required: true - ChannelReserve big.Int `json:"channel_reserve"` + ChannelReserve utils.BigInt `json:"channel_reserve"` // delegate ids // Required: true @@ -39,7 +39,7 @@ type Channel struct { // initiator amount // Required: true - InitiatorAmount big.Int `json:"initiator_amount"` + InitiatorAmount utils.BigInt `json:"initiator_amount"` // initiator id // Required: true @@ -56,7 +56,7 @@ type Channel struct { // responder amount // Required: true - ResponderAmount big.Int `json:"responder_amount"` + ResponderAmount utils.BigInt `json:"responder_amount"` // responder id // Required: true diff --git a/generated/models/channel_close_mutual_tx.go b/generated/models/channel_close_mutual_tx.go index c32a0f7e..4843400f 100644 --- a/generated/models/channel_close_mutual_tx.go +++ b/generated/models/channel_close_mutual_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ChannelCloseMutualTx channel close mutual tx @@ -25,7 +25,7 @@ type ChannelCloseMutualTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // from id // Required: true @@ -33,7 +33,7 @@ type ChannelCloseMutualTx struct { // initiator amount final // Required: true - InitiatorAmountFinal big.Int `json:"initiator_amount_final"` + InitiatorAmountFinal utils.BigInt `json:"initiator_amount_final"` // nonce // Required: true @@ -42,7 +42,7 @@ type ChannelCloseMutualTx struct { // responder amount final // Required: true - ResponderAmountFinal big.Int `json:"responder_amount_final"` + ResponderAmountFinal utils.BigInt `json:"responder_amount_final"` // ttl // Minimum: 0 diff --git a/generated/models/channel_close_solo_tx.go b/generated/models/channel_close_solo_tx.go index d4fe7017..bc86457b 100644 --- a/generated/models/channel_close_solo_tx.go +++ b/generated/models/channel_close_solo_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ChannelCloseSoloTx channel close solo tx @@ -25,7 +25,7 @@ type ChannelCloseSoloTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // from id // Required: true diff --git a/generated/models/channel_create_tx.go b/generated/models/channel_create_tx.go index c30dd46a..62c6d69f 100644 --- a/generated/models/channel_create_tx.go +++ b/generated/models/channel_create_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ChannelCreateTx channel create tx @@ -21,15 +21,15 @@ type ChannelCreateTx struct { // channel reserve // Required: true - ChannelReserve big.Int `json:"channel_reserve"` + ChannelReserve utils.BigInt `json:"channel_reserve"` // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // initiator amount // Required: true - InitiatorAmount big.Int `json:"initiator_amount"` + InitiatorAmount utils.BigInt `json:"initiator_amount"` // initiator id // Required: true @@ -46,11 +46,11 @@ type ChannelCreateTx struct { // push amount // Required: true - PushAmount big.Int `json:"push_amount"` + PushAmount utils.BigInt `json:"push_amount"` // responder amount // Required: true - ResponderAmount big.Int `json:"responder_amount"` + ResponderAmount utils.BigInt `json:"responder_amount"` // responder id // Required: true diff --git a/generated/models/channel_deposit_tx.go b/generated/models/channel_deposit_tx.go index affcb232..d2c30c29 100644 --- a/generated/models/channel_deposit_tx.go +++ b/generated/models/channel_deposit_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ChannelDepositTx channel deposit tx @@ -21,7 +21,7 @@ type ChannelDepositTx struct { // amount // Required: true - Amount big.Int `json:"amount"` + Amount utils.BigInt `json:"amount"` // channel id // Required: true @@ -29,7 +29,7 @@ type ChannelDepositTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // from id // Required: true diff --git a/generated/models/channel_force_progress_tx.go b/generated/models/channel_force_progress_tx.go index d87e1ca5..15175eb0 100644 --- a/generated/models/channel_force_progress_tx.go +++ b/generated/models/channel_force_progress_tx.go @@ -17,7 +17,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ChannelForceProgressTx channel force progress tx @@ -30,7 +30,7 @@ type ChannelForceProgressTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // from id // Required: true @@ -78,7 +78,7 @@ func (m *ChannelForceProgressTx) UnmarshalJSON(raw []byte) error { var data struct { ChannelID EncodedHash `json:"channel_id"` - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` FromID EncodedHash `json:"from_id"` @@ -153,7 +153,7 @@ func (m ChannelForceProgressTx) MarshalJSON() ([]byte, error) { b1, err = json.Marshal(struct { ChannelID EncodedHash `json:"channel_id"` - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` FromID EncodedHash `json:"from_id"` diff --git a/generated/models/channel_settle_tx.go b/generated/models/channel_settle_tx.go index 6e02fab0..10b35631 100644 --- a/generated/models/channel_settle_tx.go +++ b/generated/models/channel_settle_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ChannelSettleTx channel settle tx @@ -25,7 +25,7 @@ type ChannelSettleTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // from id // Required: true @@ -33,7 +33,7 @@ type ChannelSettleTx struct { // initiator amount final // Required: true - InitiatorAmountFinal big.Int `json:"initiator_amount_final"` + InitiatorAmountFinal utils.BigInt `json:"initiator_amount_final"` // nonce // Required: true @@ -42,7 +42,7 @@ type ChannelSettleTx struct { // responder amount final // Required: true - ResponderAmountFinal big.Int `json:"responder_amount_final"` + ResponderAmountFinal utils.BigInt `json:"responder_amount_final"` // ttl // Minimum: 0 diff --git a/generated/models/channel_sla_s_h_tx.go b/generated/models/channel_sla_s_h_tx.go index e22fa503..3768c780 100644 --- a/generated/models/channel_sla_s_h_tx.go +++ b/generated/models/channel_sla_s_h_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ChannelSLASHTx channel slash tx @@ -25,7 +25,7 @@ type ChannelSLASHTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // from id // Required: true diff --git a/generated/models/channel_snapshot_solo_tx.go b/generated/models/channel_snapshot_solo_tx.go index 7ff36fe2..2dcc46fa 100644 --- a/generated/models/channel_snapshot_solo_tx.go +++ b/generated/models/channel_snapshot_solo_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ChannelSnapshotSoloTx channel snapshot solo tx @@ -25,7 +25,7 @@ type ChannelSnapshotSoloTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // from id // Required: true diff --git a/generated/models/channel_withdraw_tx.go b/generated/models/channel_withdraw_tx.go index 210ad97c..a2a3faba 100644 --- a/generated/models/channel_withdraw_tx.go +++ b/generated/models/channel_withdraw_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ChannelWithdrawTx channel withdraw tx @@ -21,7 +21,7 @@ type ChannelWithdrawTx struct { // amount // Required: true - Amount big.Int `json:"amount"` + Amount utils.BigInt `json:"amount"` // channel id // Required: true @@ -29,7 +29,7 @@ type ChannelWithdrawTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // nonce // Required: true diff --git a/generated/models/contract_call_compute.go b/generated/models/contract_call_compute.go index e4083128..d2af0a0d 100644 --- a/generated/models/contract_call_compute.go +++ b/generated/models/contract_call_compute.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ContractCallCompute contract call compute @@ -40,7 +40,7 @@ type ContractCallCompute struct { // Transaction fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // Contract call data function (deprecated, use call) Function string `json:"function,omitempty"` diff --git a/generated/models/contract_call_tx.go b/generated/models/contract_call_tx.go index 1d2393ef..ea8d35d4 100644 --- a/generated/models/contract_call_tx.go +++ b/generated/models/contract_call_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ContractCallTx contract call tx @@ -38,7 +38,7 @@ type ContractCallTx struct { // Transaction fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // Contract gas // Required: true diff --git a/generated/models/contract_create_compute.go b/generated/models/contract_create_compute.go index 4e6b9db5..ef68d1ac 100644 --- a/generated/models/contract_create_compute.go +++ b/generated/models/contract_create_compute.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ContractCreateCompute contract create compute @@ -41,7 +41,7 @@ type ContractCreateCompute struct { // Transaction fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // Contract gas // Required: true diff --git a/generated/models/contract_create_tx.go b/generated/models/contract_create_tx.go index 0c859006..84a82b9c 100644 --- a/generated/models/contract_create_tx.go +++ b/generated/models/contract_create_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // ContractCreateTx contract create tx @@ -39,7 +39,7 @@ type ContractCreateTx struct { // Transaction fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // Contract gas // Required: true diff --git a/generated/models/name_claim_tx.go b/generated/models/name_claim_tx.go index b1aef121..86ad8e1d 100644 --- a/generated/models/name_claim_tx.go +++ b/generated/models/name_claim_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // NameClaimTx name claim tx @@ -25,7 +25,7 @@ type NameClaimTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // name // Required: true diff --git a/generated/models/name_preclaim_tx.go b/generated/models/name_preclaim_tx.go index fe3e4483..fa217546 100644 --- a/generated/models/name_preclaim_tx.go +++ b/generated/models/name_preclaim_tx.go @@ -11,7 +11,7 @@ import ( "github.com/go-openapi/errors" "github.com/go-openapi/swag" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // NamePreclaimTx name preclaim tx @@ -28,7 +28,7 @@ type NamePreclaimTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // nonce Nonce uint64 `json:"nonce,omitempty"` diff --git a/generated/models/name_revoke_tx.go b/generated/models/name_revoke_tx.go index 41ba4e3b..62b56862 100644 --- a/generated/models/name_revoke_tx.go +++ b/generated/models/name_revoke_tx.go @@ -11,7 +11,7 @@ import ( "github.com/go-openapi/errors" "github.com/go-openapi/swag" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // NameRevokeTx name revoke tx @@ -24,7 +24,7 @@ type NameRevokeTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // name id // Required: true diff --git a/generated/models/name_transfer_tx.go b/generated/models/name_transfer_tx.go index 91beffbf..d4b6ac23 100644 --- a/generated/models/name_transfer_tx.go +++ b/generated/models/name_transfer_tx.go @@ -11,7 +11,7 @@ import ( "github.com/go-openapi/errors" "github.com/go-openapi/swag" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // NameTransferTx name transfer tx @@ -24,7 +24,7 @@ type NameTransferTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // name id // Required: true diff --git a/generated/models/name_update_tx.go b/generated/models/name_update_tx.go index b1b97f07..4f5a018b 100644 --- a/generated/models/name_update_tx.go +++ b/generated/models/name_update_tx.go @@ -14,7 +14,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // NameUpdateTx name update tx @@ -31,7 +31,7 @@ type NameUpdateTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // name id // Required: true diff --git a/generated/models/oracle_extend_tx.go b/generated/models/oracle_extend_tx.go index a60f0be2..6302c3fa 100644 --- a/generated/models/oracle_extend_tx.go +++ b/generated/models/oracle_extend_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // OracleExtendTx oracle extend tx @@ -21,7 +21,7 @@ type OracleExtendTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // nonce Nonce uint64 `json:"nonce,omitempty"` diff --git a/generated/models/oracle_query.go b/generated/models/oracle_query.go index 860adedb..569d4d71 100644 --- a/generated/models/oracle_query.go +++ b/generated/models/oracle_query.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // OracleQuery oracle query @@ -21,7 +21,7 @@ type OracleQuery struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // id // Required: true diff --git a/generated/models/oracle_query_tx.go b/generated/models/oracle_query_tx.go index 77012c57..91b74e41 100644 --- a/generated/models/oracle_query_tx.go +++ b/generated/models/oracle_query_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // OracleQueryTx oracle query tx @@ -21,7 +21,7 @@ type OracleQueryTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // Sender nonce Nonce uint64 `json:"nonce,omitempty"` @@ -36,7 +36,7 @@ type OracleQueryTx struct { // query fee // Required: true - QueryFee big.Int `json:"query_fee"` + QueryFee utils.BigInt `json:"query_fee"` // query ttl // Required: true diff --git a/generated/models/oracle_register_tx.go b/generated/models/oracle_register_tx.go index 09450ce4..c636bf64 100644 --- a/generated/models/oracle_register_tx.go +++ b/generated/models/oracle_register_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // OracleRegisterTx oracle register tx @@ -25,7 +25,7 @@ type OracleRegisterTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // nonce Nonce uint64 `json:"nonce,omitempty"` @@ -36,7 +36,7 @@ type OracleRegisterTx struct { // query fee // Required: true - QueryFee big.Int `json:"query_fee"` + QueryFee utils.BigInt `json:"query_fee"` // query format // Required: true diff --git a/generated/models/oracle_respond_tx.go b/generated/models/oracle_respond_tx.go index a302e2dc..f37b7eab 100644 --- a/generated/models/oracle_respond_tx.go +++ b/generated/models/oracle_respond_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // OracleRespondTx oracle respond tx @@ -21,7 +21,7 @@ type OracleRespondTx struct { // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // Oracle nonce Nonce uint64 `json:"nonce,omitempty"` diff --git a/generated/models/registered_oracle.go b/generated/models/registered_oracle.go index 3c24aa75..4d5be5f7 100644 --- a/generated/models/registered_oracle.go +++ b/generated/models/registered_oracle.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // RegisteredOracle registered oracle @@ -25,7 +25,7 @@ type RegisteredOracle struct { // query fee // Required: true - QueryFee big.Int `json:"query_fee"` + QueryFee utils.BigInt `json:"query_fee"` // query format // Required: true diff --git a/generated/models/spend_tx.go b/generated/models/spend_tx.go index 4a9b8159..6b494a86 100644 --- a/generated/models/spend_tx.go +++ b/generated/models/spend_tx.go @@ -12,7 +12,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/validate" - big "math/big" + utils "github.com/aeternity/aepp-sdk-go/utils" ) // SpendTx spend tx @@ -21,11 +21,11 @@ type SpendTx struct { // amount // Required: true - Amount big.Int `json:"amount"` + Amount utils.BigInt `json:"amount"` // fee // Required: true - Fee big.Int `json:"fee"` + Fee utils.BigInt `json:"fee"` // nonce Nonce uint64 `json:"nonce,omitempty"` diff --git a/utils/utils.go b/utils/utils.go index a8e81ed9..656aa399 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -2,12 +2,15 @@ package utils import ( "bufio" + "errors" "fmt" + "math/big" "os" "strconv" "strings" "syscall" + "github.com/go-openapi/strfmt" gonanoid "github.com/matoous/go-nanoid" "golang.org/x/crypto/ssh/terminal" ) @@ -131,3 +134,17 @@ func AskPassword(question string) (password string, err error) { password = string(bytePassword) return } + +// BigInt is used by swagger as a big.Int type with Validate() function +type BigInt big.Int + +// Validate only checks that the number is >=0 +func (b *BigInt) Validate(formats strfmt.Registry) error { + var zero big.Int + var convertedCustomBigInt = big.Int(*b) + + if convertedCustomBigInt.Cmp(&zero) != 1 { + return errors.New("swagger deserialization: Balance Validation failed") + } + return nil +}