-
Notifications
You must be signed in to change notification settings - Fork 2
Update go version and libraries #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -414,3 +414,83 @@ func (service *constructionService) ConstructionSubmit( | |
| }, | ||
| }, nil | ||
| } | ||
|
|
||
| // ConstructionPreprocessOperations will validate the requested operations and options, | ||
| // prepare the corresponding transaction (handling native or custom currency transfers) | ||
| // and return the resulting operations along with the maximum fee and metadata required | ||
| // for the subsequent payload construction | ||
| func (service *constructionService) ConstructionPreprocessOperations( | ||
| _ context.Context, | ||
| request *types.ConstructionPreprocessOperationsRequest, | ||
| ) (*types.ConstructionPreprocessOperationsResponse, *types.Error) { | ||
| log.Debug("constructionService.ConstructionPreprocessOperations()", "construct_op", request.ConstructOp, "from_address", request.FromAddress) | ||
|
|
||
| requestOptions, err := newConstructionOptions(request.Options) | ||
| if err != nil { | ||
| return nil, service.errFactory.newErrWithOriginal(ErrConstruction, err) | ||
| } | ||
| if request.FromAddress != nil && len(*request.FromAddress) > 0 && len(requestOptions.Sender) == 0 { | ||
| requestOptions.Sender = *request.FromAddress | ||
| } | ||
|
|
||
| isNative := service.extension.isNativeCurrencySymbol(requestOptions.CurrencySymbol) | ||
| if !isNative && !service.provider.HasCustomCurrency(requestOptions.CurrencySymbol) { | ||
| return nil, service.errFactory.newErrWithOriginal(ErrConstruction, fmt.Errorf("unsupported currency: %s", requestOptions.CurrencySymbol)) | ||
| } | ||
|
|
||
| nativeCurrencySymbol := service.extension.getNativeCurrencySymbol() | ||
| if request.ConstructOp == "transfer" { | ||
| err = requestOptions.validate(nativeCurrencySymbol) | ||
| if err != nil { | ||
| return nil, service.errFactory.newErrWithOriginal(ErrConstruction, err) | ||
| } | ||
| err = validateTransferAmount(requestOptions.Amount) | ||
| if err != nil { | ||
| return nil, service.errFactory.newErrWithOriginal(ErrConstruction, err) | ||
| } | ||
| } else { | ||
| return nil, service.errFactory.newErrWithOriginal(ErrNotImplemented, fmt.Errorf("unsupported construct_op: %s", request.ConstructOp)) | ||
| } | ||
|
|
||
| tx := &data.Transaction{ | ||
| Sender: requestOptions.Sender, | ||
| Receiver: requestOptions.Receiver, | ||
| Value: requestOptions.Amount, | ||
| Data: requestOptions.Data, | ||
| } | ||
|
|
||
| if !isNative { | ||
| tx.Value = amountZero | ||
| tx.Data = service.computeDataForCustomCurrencyTransfer(requestOptions.CurrencySymbol, requestOptions.Amount) | ||
| } else if isCustomCurrencyTransfer(string(tx.Data)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may not have a very good overview of the code and this might be wrong but, shouldn't this check for other kind of transfers? Currently only the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for ESDT tokens transfer only function ESDTTransfer is supported. |
||
| return nil, service.errFactory.newErrWithOriginal( | ||
| ErrConstruction, | ||
| errors.New("for native currency transfers, option 'data' must not encode a custom currency (ESDT) transfer"), | ||
| ) | ||
| } | ||
|
|
||
| operations, err := service.createOperationsFromPreparedTx(tx) | ||
| if err != nil { | ||
| return nil, service.errFactory.newErrWithOriginal(ErrConstruction, err) | ||
| } | ||
|
|
||
| _, gasLimit, gasPrice, errTyped := service.computeFeeComponents(requestOptions, tx.Data) | ||
| if errTyped != nil { | ||
| return nil, errTyped | ||
| } | ||
|
|
||
| requestOptions.GasLimit = gasLimit | ||
| requestOptions.GasPrice = gasPrice | ||
|
|
||
| maxFee := service.computeMaxFee(tx.Data, gasLimit, gasPrice) | ||
|
|
||
| metadataBytes, err := json.Marshal(requestOptions) | ||
| if err != nil { | ||
| return nil, service.errFactory.newErrWithOriginal(ErrConstruction, err) | ||
| } | ||
| return &types.ConstructionPreprocessOperationsResponse{ | ||
| Operations: operations, | ||
| MaxFee: service.extension.valueToNativeAmount(maxFee.String()), | ||
| Metadata: new(string(metadataBytes)), | ||
| }, nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done