code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/graphql/marshallers/marshallers.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package marshallers 17 18 import ( 19 "errors" 20 "fmt" 21 "io" 22 "strconv" 23 24 v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2" 25 "code.vegaprotocol.io/vega/protos/vega" 26 vegapb "code.vegaprotocol.io/vega/protos/vega" 27 commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1" 28 datapb "code.vegaprotocol.io/vega/protos/vega/data/v1" 29 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 30 31 "github.com/99designs/gqlgen/graphql" 32 ) 33 34 var ErrUnimplemented = errors.New("unmarshaller not implemented as this API is query only") 35 36 func MarshalIndividualScope(t vega.IndividualScope) graphql.Marshaler { 37 return graphql.WriterFunc(func(w io.Writer) { 38 w.Write([]byte(strconv.Quote(t.String()))) 39 }) 40 } 41 42 func UnmarshalIndividualScope(v interface{}) (vega.IndividualScope, error) { 43 s, ok := v.(string) 44 if !ok { 45 return vega.IndividualScope_INDIVIDUAL_SCOPE_UNSPECIFIED, fmt.Errorf("expected individual scope to be a string") 46 } 47 48 t, ok := vega.IndividualScope_value[s] 49 if !ok { 50 return vega.IndividualScope_INDIVIDUAL_SCOPE_UNSPECIFIED, fmt.Errorf("failed to convert IndividualScope from GraphQL to Proto: %v", s) 51 } 52 53 return vega.IndividualScope(t), nil 54 } 55 56 func MarshalDistributionStrategy(t vega.DistributionStrategy) graphql.Marshaler { 57 return graphql.WriterFunc(func(w io.Writer) { 58 w.Write([]byte(strconv.Quote(t.String()))) 59 }) 60 } 61 62 func UnmarshalDistributionStrategy(v interface{}) (vega.DistributionStrategy, error) { 63 s, ok := v.(string) 64 if !ok { 65 return vega.DistributionStrategy_DISTRIBUTION_STRATEGY_UNSPECIFIED, fmt.Errorf("expected distribution strategy to be a string") 66 } 67 68 t, ok := vega.DistributionStrategy_value[s] 69 if !ok { 70 return vega.DistributionStrategy_DISTRIBUTION_STRATEGY_UNSPECIFIED, fmt.Errorf("failed to convert DistributionStrategy from GraphQL to Proto: %v", s) 71 } 72 73 return vega.DistributionStrategy(t), nil 74 } 75 76 func MarshalEntityScope(t vega.EntityScope) graphql.Marshaler { 77 return graphql.WriterFunc(func(w io.Writer) { 78 w.Write([]byte(strconv.Quote(t.String()))) 79 }) 80 } 81 82 func UnmarshalEntityScope(v interface{}) (vega.EntityScope, error) { 83 s, ok := v.(string) 84 if !ok { 85 return vega.EntityScope_ENTITY_SCOPE_UNSPECIFIED, fmt.Errorf("expected entity scope to be a string") 86 } 87 88 t, ok := vega.EntityScope_value[s] 89 if !ok { 90 return vega.EntityScope_ENTITY_SCOPE_UNSPECIFIED, fmt.Errorf("failed to convert EntityScope from GraphQL to Proto: %v", s) 91 } 92 93 return vega.EntityScope(t), nil 94 } 95 96 func MarshalAccountType(t vega.AccountType) graphql.Marshaler { 97 return graphql.WriterFunc(func(w io.Writer) { 98 w.Write([]byte(strconv.Quote(t.String()))) 99 }) 100 } 101 102 func UnmarshalAccountType(v interface{}) (vega.AccountType, error) { 103 s, ok := v.(string) 104 if !ok { 105 return vega.AccountType_ACCOUNT_TYPE_UNSPECIFIED, fmt.Errorf("expected account type to be a string") 106 } 107 108 t, ok := vega.AccountType_value[s] 109 if !ok { 110 return vega.AccountType_ACCOUNT_TYPE_UNSPECIFIED, fmt.Errorf("failed to convert AccountType from GraphQL to Proto: %v", s) 111 } 112 113 return vega.AccountType(t), nil 114 } 115 116 func MarshalSide(s vega.Side) graphql.Marshaler { 117 return graphql.WriterFunc(func(w io.Writer) { 118 w.Write([]byte(strconv.Quote(s.String()))) 119 }) 120 } 121 122 func UnmarshalSide(v interface{}) (vega.Side, error) { 123 s, ok := v.(string) 124 if !ok { 125 return vega.Side_SIDE_UNSPECIFIED, fmt.Errorf("expected account type to be a string") 126 } 127 128 side, ok := vega.Side_value[s] 129 if !ok { 130 return vega.Side_SIDE_UNSPECIFIED, fmt.Errorf("failed to convert AccountType from GraphQL to Proto: %v", s) 131 } 132 133 return vega.Side(side), nil 134 } 135 136 func MarshalProposalState(s vega.Proposal_State) graphql.Marshaler { 137 return graphql.WriterFunc(func(w io.Writer) { 138 w.Write([]byte(strconv.Quote(s.String()))) 139 }) 140 } 141 142 func UnmarshalProposalState(v interface{}) (vega.Proposal_State, error) { 143 s, ok := v.(string) 144 if !ok { 145 return vega.Proposal_STATE_UNSPECIFIED, fmt.Errorf("expected proposal state to be a string") 146 } 147 148 side, ok := vega.Proposal_State_value[s] 149 if !ok { 150 return vega.Proposal_STATE_UNSPECIFIED, fmt.Errorf("failed to convert ProposalState from GraphQL to Proto: %v", s) 151 } 152 153 return vega.Proposal_State(side), nil 154 } 155 156 func MarshalTransferType(t vega.TransferType) graphql.Marshaler { 157 return graphql.WriterFunc(func(w io.Writer) { 158 w.Write([]byte(strconv.Quote(t.String()))) 159 }) 160 } 161 162 func MarshalTransferScope(s v2.ListTransfersRequest_Scope) graphql.Marshaler { 163 return graphql.WriterFunc(func(w io.Writer) { 164 w.Write([]byte(strconv.Quote(s.String()))) 165 }) 166 } 167 168 func UnmarshalTransferScope(v interface{}) (v2.ListTransfersRequest_Scope, error) { 169 s, ok := v.(string) 170 if !ok { 171 return v2.ListTransfersRequest_SCOPE_UNSPECIFIED, fmt.Errorf("expected transfer scope to be a string") 172 } 173 174 t, ok := v2.ListGovernanceDataRequest_Type_value[s] 175 if !ok { 176 return v2.ListTransfersRequest_SCOPE_UNSPECIFIED, fmt.Errorf("failed to convert transfer scope from GraphQL to Proto: %v", s) 177 } 178 179 return v2.ListTransfersRequest_Scope(t), nil 180 } 181 182 func UnmarshalTransferType(v interface{}) (vega.TransferType, error) { 183 s, ok := v.(string) 184 if !ok { 185 return vega.TransferType_TRANSFER_TYPE_UNSPECIFIED, fmt.Errorf("expected transfer type to be a string") 186 } 187 188 t, ok := vega.TransferType_value[s] 189 if !ok { 190 return vega.TransferType_TRANSFER_TYPE_UNSPECIFIED, fmt.Errorf("failed to convert TransferType from GraphQL to Proto: %v", s) 191 } 192 193 return vega.TransferType(t), nil 194 } 195 196 func MarshalTransferStatus(s eventspb.Transfer_Status) graphql.Marshaler { 197 return graphql.WriterFunc(func(w io.Writer) { 198 w.Write([]byte(strconv.Quote(s.String()))) 199 }) 200 } 201 202 func UnmarshalTransferStatus(v interface{}) (eventspb.Transfer_Status, error) { 203 s, ok := v.(string) 204 if !ok { 205 return eventspb.Transfer_STATUS_UNSPECIFIED, fmt.Errorf("expected transfer status to be a string") 206 } 207 208 t, ok := eventspb.Transfer_Status_value[s] 209 if !ok { 210 return eventspb.Transfer_STATUS_UNSPECIFIED, fmt.Errorf("failed to convert TransferStatus from GraphQL to Proto: %v", s) 211 } 212 213 return eventspb.Transfer_Status(t), nil 214 } 215 216 func MarshalDispatchMetric(s vega.DispatchMetric) graphql.Marshaler { 217 return graphql.WriterFunc(func(w io.Writer) { 218 w.Write([]byte(strconv.Quote(s.String()))) 219 }) 220 } 221 222 func UnmarshalDispatchMetric(v interface{}) (vega.DispatchMetric, error) { 223 return vega.DispatchMetric_DISPATCH_METRIC_UNSPECIFIED, ErrUnimplemented 224 } 225 226 func MarshalNodeStatus(s vega.NodeStatus) graphql.Marshaler { 227 return graphql.WriterFunc(func(w io.Writer) { 228 w.Write([]byte(strconv.Quote(s.String()))) 229 }) 230 } 231 232 func UnmarshalNodeStatus(v interface{}) (vega.NodeStatus, error) { 233 return vega.NodeStatus_NODE_STATUS_UNSPECIFIED, ErrUnimplemented 234 } 235 236 func MarshalAssetStatus(s vega.Asset_Status) graphql.Marshaler { 237 return graphql.WriterFunc(func(w io.Writer) { 238 w.Write([]byte(strconv.Quote(s.String()))) 239 }) 240 } 241 242 func UnmarshalAssetStatus(v interface{}) (vega.Asset_Status, error) { 243 return vega.Asset_STATUS_UNSPECIFIED, ErrUnimplemented 244 } 245 246 func MarshalNodeSignatureKind(s commandspb.NodeSignatureKind) graphql.Marshaler { 247 return graphql.WriterFunc(func(w io.Writer) { 248 w.Write([]byte(strconv.Quote(s.String()))) 249 }) 250 } 251 252 func UnmarshalNodeSignatureKind(v interface{}) (commandspb.NodeSignatureKind, error) { 253 return commandspb.NodeSignatureKind_NODE_SIGNATURE_KIND_UNSPECIFIED, ErrUnimplemented 254 } 255 256 func MarshalOracleSpecStatus(s vegapb.DataSourceSpec_Status) graphql.Marshaler { 257 return graphql.WriterFunc(func(w io.Writer) { 258 w.Write([]byte(strconv.Quote(s.String()))) 259 }) 260 } 261 262 func UnmarshalOracleSpecStatus(v interface{}) (vegapb.DataSourceSpec_Status, error) { 263 return vegapb.DataSourceSpec_STATUS_UNSPECIFIED, ErrUnimplemented 264 } 265 266 func MarshalPropertyKeyType(s datapb.PropertyKey_Type) graphql.Marshaler { 267 return graphql.WriterFunc(func(w io.Writer) { 268 w.Write([]byte(strconv.Quote(s.String()))) 269 }) 270 } 271 272 func UnmarshalPropertyKeyType(v interface{}) (datapb.PropertyKey_Type, error) { 273 return datapb.PropertyKey_TYPE_UNSPECIFIED, ErrUnimplemented 274 } 275 276 func MarshalConditionOperator(s datapb.Condition_Operator) graphql.Marshaler { 277 return graphql.WriterFunc(func(w io.Writer) { 278 w.Write([]byte(strconv.Quote(s.String()))) 279 }) 280 } 281 282 func UnmarshalConditionOperator(v interface{}) (datapb.Condition_Operator, error) { 283 return datapb.Condition_OPERATOR_UNSPECIFIED, ErrUnimplemented 284 } 285 286 func MarshalVoteValue(s vega.Vote_Value) graphql.Marshaler { 287 return graphql.WriterFunc(func(w io.Writer) { 288 w.Write([]byte(strconv.Quote(s.String()))) 289 }) 290 } 291 292 func UnmarshalVoteValue(v interface{}) (vega.Vote_Value, error) { 293 return vega.Vote_VALUE_UNSPECIFIED, ErrUnimplemented 294 } 295 296 func MarshalAuctionTrigger(s vega.AuctionTrigger) graphql.Marshaler { 297 return graphql.WriterFunc(func(w io.Writer) { 298 w.Write([]byte(strconv.Quote(s.String()))) 299 }) 300 } 301 302 func UnmarshalAuctionTrigger(v interface{}) (vega.AuctionTrigger, error) { 303 return vega.AuctionTrigger_AUCTION_TRIGGER_UNSPECIFIED, ErrUnimplemented 304 } 305 306 func MarshalStakeLinkingStatus(s eventspb.StakeLinking_Status) graphql.Marshaler { 307 return graphql.WriterFunc(func(w io.Writer) { 308 w.Write([]byte(strconv.Quote(s.String()))) 309 }) 310 } 311 312 func UnmarshalStakeLinkingStatus(v interface{}) (eventspb.StakeLinking_Status, error) { 313 return eventspb.StakeLinking_STATUS_UNSPECIFIED, ErrUnimplemented 314 } 315 316 func MarshalStakeLinkingType(s eventspb.StakeLinking_Type) graphql.Marshaler { 317 return graphql.WriterFunc(func(w io.Writer) { 318 w.Write([]byte(strconv.Quote(s.String()))) 319 }) 320 } 321 322 func UnmarshalStakeLinkingType(v interface{}) (eventspb.StakeLinking_Type, error) { 323 return eventspb.StakeLinking_TYPE_UNSPECIFIED, ErrUnimplemented 324 } 325 326 func MarshalWithdrawalStatus(s vega.Withdrawal_Status) graphql.Marshaler { 327 return graphql.WriterFunc(func(w io.Writer) { 328 w.Write([]byte(strconv.Quote(s.String()))) 329 }) 330 } 331 332 func UnmarshalWithdrawalStatus(v interface{}) (vega.Withdrawal_Status, error) { 333 return vega.Withdrawal_STATUS_UNSPECIFIED, ErrUnimplemented 334 } 335 336 func MarshalDepositStatus(s vega.Deposit_Status) graphql.Marshaler { 337 return graphql.WriterFunc(func(w io.Writer) { 338 w.Write([]byte(strconv.Quote(s.String()))) 339 }) 340 } 341 342 func UnmarshalDepositStatus(v interface{}) (vega.Deposit_Status, error) { 343 return vega.Deposit_STATUS_UNSPECIFIED, ErrUnimplemented 344 } 345 346 func MarshalOrderStatus(s vega.Order_Status) graphql.Marshaler { 347 return graphql.WriterFunc(func(w io.Writer) { 348 w.Write([]byte(strconv.Quote(s.String()))) 349 }) 350 } 351 352 func UnmarshalOrderStatus(v interface{}) (vega.Order_Status, error) { 353 s, ok := v.(string) 354 if !ok { 355 return vega.Order_STATUS_UNSPECIFIED, fmt.Errorf("exoected order status to be a string") 356 } 357 358 t, ok := vega.Order_Status_value[s] 359 if !ok { 360 return vega.Order_STATUS_UNSPECIFIED, fmt.Errorf("failed to convert order status from GraphQL to Proto: %v", s) 361 } 362 363 return vega.Order_Status(t), nil 364 } 365 366 func MarshalOrderTimeInForce(s vega.Order_TimeInForce) graphql.Marshaler { 367 return graphql.WriterFunc(func(w io.Writer) { 368 w.Write([]byte(strconv.Quote(s.String()))) 369 }) 370 } 371 372 func UnmarshalOrderTimeInForce(v interface{}) (vega.Order_TimeInForce, error) { 373 s, ok := v.(string) 374 if !ok { 375 return vega.Order_TIME_IN_FORCE_UNSPECIFIED, fmt.Errorf("expected order time in force to be a string") 376 } 377 378 t, ok := vega.Order_TimeInForce_value[s] 379 if !ok { 380 return vega.Order_TIME_IN_FORCE_UNSPECIFIED, fmt.Errorf("failed to convert TimeInForce from GraphQL to Proto: %v", s) 381 } 382 383 return vega.Order_TimeInForce(t), nil 384 } 385 386 func MarshalPeggedReference(s vega.PeggedReference) graphql.Marshaler { 387 return graphql.WriterFunc(func(w io.Writer) { 388 w.Write([]byte(strconv.Quote(s.String()))) 389 }) 390 } 391 392 func UnmarshalPeggedReference(v interface{}) (vega.PeggedReference, error) { 393 return vega.PeggedReference_PEGGED_REFERENCE_UNSPECIFIED, ErrUnimplemented 394 } 395 396 func MarshalProposalRejectionReason(s vega.ProposalError) graphql.Marshaler { 397 return graphql.WriterFunc(func(w io.Writer) { 398 w.Write([]byte(strconv.Quote(s.String()))) 399 }) 400 } 401 402 func UnmarshalProposalRejectionReason(v interface{}) (vega.ProposalError, error) { 403 return vega.ProposalError_PROPOSAL_ERROR_UNSPECIFIED, ErrUnimplemented 404 } 405 406 func MarshalOrderRejectionReason(s vega.OrderError) graphql.Marshaler { 407 return graphql.WriterFunc(func(w io.Writer) { 408 w.Write([]byte(strconv.Quote(s.String()))) 409 }) 410 } 411 412 func UnmarshalOrderRejectionReason(v interface{}) (vega.OrderError, error) { 413 return vega.OrderError_ORDER_ERROR_UNSPECIFIED, ErrUnimplemented 414 } 415 416 func MarshalStopOrderRejectionReason(s vega.StopOrder_RejectionReason) graphql.Marshaler { 417 return graphql.WriterFunc(func(w io.Writer) { 418 w.Write([]byte(strconv.Quote(s.String()))) 419 }) 420 } 421 422 func UnmarshalStopOrderRejectionReason(v interface{}) (vega.StopOrder_RejectionReason, error) { 423 s, ok := v.(string) 424 if !ok { 425 return vega.StopOrder_REJECTION_REASON_UNSPECIFIED, fmt.Errorf("expected stop order rejection reason to be a string") 426 } 427 428 t, ok := vega.StopOrder_RejectionReason_value[s] 429 if !ok { 430 return vega.StopOrder_REJECTION_REASON_UNSPECIFIED, fmt.Errorf("failed to convert StopOrderRejectionReason from GraphQL to Proto: %v", s) 431 } 432 433 return vega.StopOrder_RejectionReason(t), nil 434 } 435 436 func MarshalOrderType(s vega.Order_Type) graphql.Marshaler { 437 return graphql.WriterFunc(func(w io.Writer) { 438 w.Write([]byte(strconv.Quote(s.String()))) 439 }) 440 } 441 442 func UnmarshalOrderType(v interface{}) (vega.Order_Type, error) { 443 s, ok := v.(string) 444 if !ok { 445 return vega.Order_TYPE_UNSPECIFIED, fmt.Errorf("expected order type to be a string") 446 } 447 448 t, ok := vega.Order_Type_value[s] 449 if !ok { 450 return vega.Order_TYPE_UNSPECIFIED, fmt.Errorf("failed to convert OrderType from GraphQL to Proto: %v", s) 451 } 452 453 return vega.Order_Type(t), nil 454 } 455 456 func MarshalMarketState(s vega.Market_State) graphql.Marshaler { 457 return graphql.WriterFunc(func(w io.Writer) { 458 w.Write([]byte(strconv.Quote(s.String()))) 459 }) 460 } 461 462 func UnmarshalMarketState(v interface{}) (vega.Market_State, error) { 463 return vega.Market_STATE_UNSPECIFIED, ErrUnimplemented 464 } 465 466 func MarshalMarketTradingMode(s vega.Market_TradingMode) graphql.Marshaler { 467 return graphql.WriterFunc(func(w io.Writer) { 468 w.Write([]byte(strconv.Quote(s.String()))) 469 }) 470 } 471 472 func UnmarshalMarketTradingMode(v interface{}) (vega.Market_TradingMode, error) { 473 return vega.Market_TRADING_MODE_UNSPECIFIED, ErrUnimplemented 474 } 475 476 func MarshalInterval(s vega.Interval) graphql.Marshaler { 477 return graphql.WriterFunc(func(w io.Writer) { 478 w.Write([]byte(strconv.Quote(s.String()))) 479 }) 480 } 481 482 func UnmarshalInterval(v interface{}) (vega.Interval, error) { 483 s, ok := v.(string) 484 if !ok { 485 return vega.Interval_INTERVAL_UNSPECIFIED, fmt.Errorf("expected interval in force to be a string") 486 } 487 488 t, ok := vega.Interval_value[s] 489 if !ok { 490 return vega.Interval_INTERVAL_UNSPECIFIED, fmt.Errorf("failed to convert Interval from GraphQL to Proto: %v", s) 491 } 492 493 return vega.Interval(t), nil 494 } 495 496 func MarshalProposalType(s v2.ListGovernanceDataRequest_Type) graphql.Marshaler { 497 return graphql.WriterFunc(func(w io.Writer) { 498 w.Write([]byte(strconv.Quote(s.String()))) 499 }) 500 } 501 502 func UnmarshalProposalType(v interface{}) (v2.ListGovernanceDataRequest_Type, error) { 503 s, ok := v.(string) 504 if !ok { 505 return v2.ListGovernanceDataRequest_TYPE_UNSPECIFIED, fmt.Errorf("expected proposal type in force to be a string") 506 } 507 508 t, ok := v2.ListGovernanceDataRequest_Type_value[s] 509 if !ok { 510 return v2.ListGovernanceDataRequest_TYPE_UNSPECIFIED, fmt.Errorf("failed to convert proposal type from GraphQL to Proto: %v", s) 511 } 512 513 return v2.ListGovernanceDataRequest_Type(t), nil 514 } 515 516 func MarshalLiquidityProvisionStatus(s vega.LiquidityProvision_Status) graphql.Marshaler { 517 return graphql.WriterFunc(func(w io.Writer) { 518 w.Write([]byte(strconv.Quote(s.String()))) 519 }) 520 } 521 522 func UnmarshalLiquidityProvisionStatus(v interface{}) (vega.LiquidityProvision_Status, error) { 523 return vega.LiquidityProvision_STATUS_UNSPECIFIED, ErrUnimplemented 524 } 525 526 func MarshalTradeType(s vega.Trade_Type) graphql.Marshaler { 527 return graphql.WriterFunc(func(w io.Writer) { 528 w.Write([]byte(strconv.Quote(s.String()))) 529 }) 530 } 531 532 func UnmarshalTradeType(v interface{}) (vega.Trade_Type, error) { 533 return vega.Trade_TYPE_UNSPECIFIED, ErrUnimplemented 534 } 535 536 func MarshalValidatorStatus(s vega.ValidatorNodeStatus) graphql.Marshaler { 537 return graphql.WriterFunc(func(w io.Writer) { 538 w.Write([]byte(strconv.Quote(s.String()))) 539 }) 540 } 541 542 func UnmarshalValidatorStatus(v interface{}) (vega.ValidatorNodeStatus, error) { 543 return vega.ValidatorNodeStatus_VALIDATOR_NODE_STATUS_UNSPECIFIED, ErrUnimplemented 544 } 545 546 func MarshalProtocolUpgradeProposalStatus(s eventspb.ProtocolUpgradeProposalStatus) graphql.Marshaler { 547 return graphql.WriterFunc(func(w io.Writer) { 548 w.Write([]byte(strconv.Quote(s.String()))) 549 }) 550 } 551 552 func UnmarshalProtocolUpgradeProposalStatus(v interface{}) (eventspb.ProtocolUpgradeProposalStatus, error) { 553 s, ok := v.(string) 554 if !ok { 555 return eventspb.ProtocolUpgradeProposalStatus_PROTOCOL_UPGRADE_PROPOSAL_STATUS_UNSPECIFIED, fmt.Errorf("expected proposal type in force to be a string") 556 } 557 558 t, ok := eventspb.ProtocolUpgradeProposalStatus_value[s] // v2.ListGovernanceDataRequest_Type_value[s] 559 if !ok { 560 return eventspb.ProtocolUpgradeProposalStatus_PROTOCOL_UPGRADE_PROPOSAL_STATUS_UNSPECIFIED, fmt.Errorf("failed to convert proposal type from GraphQL to Proto: %v", s) 561 } 562 563 return eventspb.ProtocolUpgradeProposalStatus(t), nil 564 } 565 566 func MarshalPositionStatus(s vega.PositionStatus) graphql.Marshaler { 567 return graphql.WriterFunc(func(w io.Writer) { 568 w.Write([]byte(strconv.Quote(s.String()))) 569 }) 570 } 571 572 func UnmarshalPositionStatus(v interface{}) (vega.PositionStatus, error) { 573 s, ok := v.(string) 574 if !ok { 575 return vega.PositionStatus_POSITION_STATUS_UNSPECIFIED, fmt.Errorf("expected position status to be a string") 576 } 577 t, ok := vega.PositionStatus_value[s] 578 if !ok { 579 return vega.PositionStatus_POSITION_STATUS_UNSPECIFIED, fmt.Errorf("failed to convert position status to Proto: %v", s) 580 } 581 return vega.PositionStatus(t), nil 582 } 583 584 func MarshalStopOrderStatus(s vega.StopOrder_Status) graphql.Marshaler { 585 return graphql.WriterFunc(func(w io.Writer) { 586 w.Write([]byte(strconv.Quote(s.String()))) 587 }) 588 } 589 590 func UnmarshalStopOrderStatus(v interface{}) (vega.StopOrder_Status, error) { 591 s, ok := v.(string) 592 if !ok { 593 return vega.StopOrder_STATUS_UNSPECIFIED, fmt.Errorf("expected stop order status to be a string") 594 } 595 t, ok := vega.StopOrder_Status_value[s] 596 if !ok { 597 return vega.StopOrder_STATUS_UNSPECIFIED, fmt.Errorf("failed to convert stop order status to Proto: %v", s) 598 } 599 return vega.StopOrder_Status(t), nil 600 } 601 602 func MarshalStopOrderExpiryStrategy(s vega.StopOrder_ExpiryStrategy) graphql.Marshaler { 603 return graphql.WriterFunc(func(w io.Writer) { 604 w.Write([]byte(strconv.Quote(s.String()))) 605 }) 606 } 607 608 func UnmarshalStopOrderExpiryStrategy(v interface{}) (vega.StopOrder_ExpiryStrategy, error) { 609 s, ok := v.(string) 610 if !ok { 611 return vega.StopOrder_EXPIRY_STRATEGY_UNSPECIFIED, fmt.Errorf("expected stop order expiry strategy to be a string") 612 } 613 t, ok := vega.StopOrder_ExpiryStrategy_value[s] 614 if !ok { 615 return vega.StopOrder_EXPIRY_STRATEGY_UNSPECIFIED, fmt.Errorf("failed to convert stop order expiry strategy to Proto: %v", s) 616 } 617 return vega.StopOrder_ExpiryStrategy(t), nil 618 } 619 620 func MarshalStopOrderTriggerDirection(s vega.StopOrder_TriggerDirection) graphql.Marshaler { 621 return graphql.WriterFunc(func(w io.Writer) { 622 w.Write([]byte(strconv.Quote(s.String()))) 623 }) 624 } 625 626 func UnmarshalStopOrderTriggerDirection(v interface{}) (vega.StopOrder_TriggerDirection, error) { 627 s, ok := v.(string) 628 if !ok { 629 return vega.StopOrder_TRIGGER_DIRECTION_UNSPECIFIED, fmt.Errorf("expected stop order trigger direction to be a string") 630 } 631 t, ok := vega.StopOrder_TriggerDirection_value[s] 632 if !ok { 633 return vega.StopOrder_TRIGGER_DIRECTION_UNSPECIFIED, fmt.Errorf("failed to convert stop order trigger direction to Proto: %v", s) 634 } 635 return vega.StopOrder_TriggerDirection(t), nil 636 } 637 638 func MarshalStopOrderSizeOverrideSetting(s vega.StopOrder_SizeOverrideSetting) graphql.Marshaler { 639 return graphql.WriterFunc(func(w io.Writer) { 640 w.Write([]byte(strconv.Quote(s.String()))) 641 }) 642 } 643 644 func UnmarshalStopOrderSizeOverrideSetting(v interface{}) (vega.StopOrder_SizeOverrideSetting, error) { 645 s, ok := v.(string) 646 if !ok { 647 return vega.StopOrder_SIZE_OVERRIDE_SETTING_UNSPECIFIED, fmt.Errorf("expected stop order size override setting to be a string") 648 } 649 t, ok := vega.StopOrder_SizeOverrideSetting_value[s] 650 if !ok { 651 return vega.StopOrder_SIZE_OVERRIDE_SETTING_UNSPECIFIED, fmt.Errorf("failed to convert stop order size override setting to Proto: %v", s) 652 } 653 return vega.StopOrder_SizeOverrideSetting(t), nil 654 } 655 656 func MarshalFundingPeriodDataPointSource(s eventspb.FundingPeriodDataPoint_Source) graphql.Marshaler { 657 return graphql.WriterFunc(func(w io.Writer) { 658 w.Write([]byte(strconv.Quote(s.String()))) 659 }) 660 } 661 662 func UnmarshalFundingPeriodDataPointSource(v interface{}) (eventspb.FundingPeriodDataPoint_Source, error) { 663 s, ok := v.(string) 664 if !ok { 665 return eventspb.FundingPeriodDataPoint_SOURCE_UNSPECIFIED, fmt.Errorf("expected funding period source to be a string") 666 } 667 t, ok := eventspb.FundingPeriodDataPoint_Source_value[s] 668 if !ok { 669 return eventspb.FundingPeriodDataPoint_SOURCE_UNSPECIFIED, fmt.Errorf("failed to convert funding period source to Proto: %v", s) 670 } 671 return eventspb.FundingPeriodDataPoint_Source(t), nil 672 } 673 674 func MarshalLiquidityFeeMethod(s vega.LiquidityFeeSettings_Method) graphql.Marshaler { 675 return graphql.WriterFunc(func(w io.Writer) { 676 w.Write([]byte(strconv.Quote(s.String()))) 677 }) 678 } 679 680 func UnmarshalLiquidityFeeMethod(v interface{}) (vega.LiquidityFeeSettings_Method, error) { 681 s, ok := v.(string) 682 if !ok { 683 return vega.LiquidityFeeSettings_METHOD_UNSPECIFIED, fmt.Errorf("expected method state to be a string") 684 } 685 686 side, ok := vega.Proposal_State_value[s] 687 if !ok { 688 return vega.LiquidityFeeSettings_METHOD_UNSPECIFIED, fmt.Errorf("failed to convert method from GraphQL to Proto: %v", s) 689 } 690 691 return vega.LiquidityFeeSettings_Method(side), nil 692 } 693 694 func MarshalMarginMode(s vega.MarginMode) graphql.Marshaler { 695 return graphql.WriterFunc(func(w io.Writer) { 696 w.Write([]byte(strconv.Quote(s.String()))) 697 }) 698 } 699 700 func UnmarshalMarginMode(v interface{}) (vega.MarginMode, error) { 701 s, ok := v.(string) 702 if !ok { 703 return vega.MarginMode_MARGIN_MODE_UNSPECIFIED, fmt.Errorf("expected margin mode to be a string") 704 } 705 706 side, ok := vega.MarginMode_value[s] 707 if !ok { 708 return vega.MarginMode_MARGIN_MODE_UNSPECIFIED, fmt.Errorf("failed to convert margin mode from GraphQL to Proto: %v", s) 709 } 710 711 return vega.MarginMode(side), nil 712 } 713 714 func MarshalAMMStatus(s eventspb.AMM_Status) graphql.Marshaler { 715 return graphql.WriterFunc(func(w io.Writer) { 716 w.Write([]byte(strconv.Quote(s.String()))) 717 }) 718 } 719 720 func UnmarshalAMMStatus(v interface{}) (eventspb.AMM_Status, error) { 721 s, ok := v.(string) 722 if !ok { 723 return eventspb.AMM_STATUS_UNSPECIFIED, fmt.Errorf("expected AMM status to be a string") 724 } 725 726 status, ok := eventspb.AMM_Status_value[s] 727 if !ok { 728 return eventspb.AMM_STATUS_UNSPECIFIED, fmt.Errorf("failed to convert AMM status from GraphQL to Proto: %v", s) 729 } 730 731 return eventspb.AMM_Status(status), nil 732 } 733 734 func MarshalAMMStatusReason(s eventspb.AMM_StatusReason) graphql.Marshaler { 735 return graphql.WriterFunc(func(w io.Writer) { 736 w.Write([]byte(strconv.Quote(s.String()))) 737 }) 738 } 739 740 func UnmarshalAMMStatusReason(v interface{}) (eventspb.AMM_StatusReason, error) { 741 s, ok := v.(string) 742 if !ok { 743 return eventspb.AMM_STATUS_REASON_UNSPECIFIED, fmt.Errorf("expected AMM status reason to be a string") 744 } 745 746 status, ok := eventspb.AMM_StatusReason_value[s] 747 if !ok { 748 return eventspb.AMM_STATUS_REASON_UNSPECIFIED, fmt.Errorf("failed to convert AMM status reason from GraphQL to Proto: %v", s) 749 } 750 751 return eventspb.AMM_StatusReason(status), nil 752 } 753 754 func MarshalEstimatedAMMError(s v2.EstimateAMMBoundsResponse_AMMError) graphql.Marshaler { 755 return graphql.WriterFunc(func(w io.Writer) { 756 w.Write([]byte(strconv.Quote(s.String()))) 757 }) 758 } 759 760 func UnmarshalEstimatedAMMError(v interface{}) (v2.EstimateAMMBoundsResponse_AMMError, error) { 761 s, ok := v.(string) 762 if !ok { 763 return v2.EstimateAMMBoundsResponse_AMM_ERROR_UNSPECIFIED, fmt.Errorf("expected Estimated AMM error to be a string") 764 } 765 766 status, ok := v2.EstimateAMMBoundsResponse_AMMError_value[s] 767 if !ok { 768 return v2.EstimateAMMBoundsResponse_AMM_ERROR_UNSPECIFIED, fmt.Errorf("failed to convert Estimated AMM error from GraphQL to Proto: %v", s) 769 } 770 771 return v2.EstimateAMMBoundsResponse_AMMError(status), nil 772 }