Skip to content

Commit

Permalink
fix rpc sdk utxo lock hash
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Feb 19, 2024
1 parent 0086a10 commit 9d7d0df
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions rpc/utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,36 @@ import (
"encoding/json"

"github.com/MixinNetwork/mixin/common"
"github.com/MixinNetwork/mixin/crypto"
)

func GetUTXO(rpc, hash string, index uint64) (*common.UTXOWithLock, error) {
data, err := callMixinRPC(rpc, "getutxo", []any{hash, index})
if err != nil {
return nil, err
}
var out common.UTXOWithLock
var out struct {
Type uint8 `json:"type"`
Hash crypto.Hash `json:"hash"`
Index uint `json:"index"`
Amount common.Integer `json:"amount"`
Keys []*crypto.Key `json:"keys"`
Script common.Script `json:"script"`
Mask *crypto.Key `json:"mask"`
LockHash crypto.Hash `json:"lock"`
}
err = json.Unmarshal(data, &out)
if err != nil {
panic(string(data))
}
return &out, err

utxo := &common.UTXOWithLock{LockHash: out.LockHash}
utxo.Type = out.Type
utxo.Hash = out.Hash
utxo.Index = out.Index
utxo.Amount = out.Amount
utxo.Keys = out.Keys
utxo.Script = out.Script
utxo.Mask = *out.Mask
return utxo, nil
}

0 comments on commit 9d7d0df

Please sign in to comment.