github.com/deroproject/derosuite@v2.1.6-1.0.20200307070847-0f2e589c7a2b+incompatible/walletapi/rpc_split_integrated_address.go (about) 1 // Copyright 2017-2018 DERO Project. All rights reserved. 2 // Use of this source code in any form is governed by RESEARCH license. 3 // license can be found in the LICENSE file. 4 // GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8 5 // 6 // 7 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 8 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 9 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 10 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 12 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 13 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 14 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 15 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 17 package walletapi 18 19 import "fmt" 20 import "context" 21 import "encoding/hex" 22 23 //import "log" 24 //import "net/http" 25 26 import "github.com/romana/rlog" 27 import "github.com/intel-go/fastjson" 28 import "github.com/osamingo/jsonrpc" 29 30 import "github.com/deroproject/derosuite/config" 31 import "github.com/deroproject/derosuite/address" 32 import "github.com/deroproject/derosuite/structures" 33 34 type Split_Integrated_Address_Handler struct { // this has access to the wallet 35 r *RPCServer 36 } 37 38 func (h Split_Integrated_Address_Handler) ServeJSONRPC(c context.Context, params *fastjson.RawMessage) (interface{}, *jsonrpc.Error) { 39 40 var p structures.Split_Integrated_Address_Params 41 var result structures.Split_Integrated_Address_Result 42 //var result structures.Transfer_Result 43 //var err error 44 45 if errp := jsonrpc.Unmarshal(params, &p); errp != nil { 46 rlog.Errorf("Could not parse split_integrated_address json, err %s\n", errp) 47 return nil, &jsonrpc.Error{Code: -2, Message: fmt.Sprintf("Could not parse split_integrated_address json, err %s", errp)} 48 } 49 50 if p.Integrated_Address == "" { 51 return nil, &jsonrpc.Error{Code: -2, Message: fmt.Sprintf("Could not find integrated address as parameter")} 52 } 53 54 addr, err := address.NewAddress(p.Integrated_Address) 55 if err != nil { 56 return nil, &jsonrpc.Error{Code: -2, Message: fmt.Sprintf("Error parsing integrated address err %s", err)} 57 } 58 59 if !addr.IsDERONetwork() { 60 return nil, &jsonrpc.Error{Code: -2, Message: fmt.Sprintf("integrated address does not belong to DERO network")} 61 } 62 63 if !addr.IsIntegratedAddress() { 64 return nil, &jsonrpc.Error{Code: -2, Message: fmt.Sprintf("address %s is NOT an integrated address", addr.String())} 65 } 66 67 if addr.Network == config.Mainnet.Public_Address_Prefix_Integrated { 68 addr.Network = config.Mainnet.Public_Address_Prefix 69 } else { 70 addr.Network = config.Testnet.Public_Address_Prefix 71 } 72 73 payment_id := addr.PaymentID 74 75 addr.PaymentID = addr.PaymentID[:0] 76 77 result.Standard_Address = addr.String() 78 result.Payment_id = hex.EncodeToString(payment_id) 79 return result, nil 80 }