OSDN Git Service

add getRecipientPublicKey
authorChengcheng Zhang <943420582@qq.com>
Sun, 8 Sep 2019 13:20:05 +0000 (21:20 +0800)
committerChengcheng Zhang <943420582@qq.com>
Sun, 8 Sep 2019 13:20:05 +0000 (21:20 +0800)
swap/htlc.go

index 8f73360..97ac0a0 100644 (file)
@@ -4,6 +4,7 @@ import (
        "errors"
        "fmt"
        "strconv"
+       "strings"
 )
 
 var (
@@ -199,6 +200,20 @@ func decodeRawTransaction(rawTransaction string, contractValue AssetAmount) (str
        return "", "", errFailedGetSignData
 }
 
+func getRecipientPublicKey(contractControlProgram string) (string, error) {
+       payload := []byte(fmt.Sprintf(
+               decodeProgramPayload,
+               contractControlProgram,
+       ))
+       res := new(decodeProgramResponse)
+       if err := request(decodeProgramURL, payload, res); err != nil {
+               return "", err
+       }
+
+       publicKey := strings.Fields(res.Instructions)[5]
+       return publicKey, nil
+}
+
 type signUnlockHTLCContractTransactionRequest struct {
        Password    string                                     `json:"password"`
        Transaction buildUnlockHTLCContractTransactionResponse `json:"transaction"`