fix: scan v1

This commit is contained in:
Trinity 2025-11-07 15:07:35 +07:00
parent 3ab2b57835
commit a9fe28d5ea

View File

@ -744,23 +744,38 @@ func (h *GprcHandler) Scan(ctx context.Context, req *nockchain.ScanRequest) (*no
continue
}
address := ""
if req.Version == 0 {
address = base58.Encode(childKey.PublicKey)
} else {
pkPoint, err := crypto.CheetaPointFromBytes(childKey.PublicKey)
if err != nil {
return nil, err
}
pkHash := HashPubkey(pkPoint)
address = crypto.Tip5HashToBase58(pkHash)
pkPoint, err := crypto.CheetaPointFromBytes(childKey.PublicKey)
if err != nil {
return nil, err
}
pkHash := HashPubkey(pkPoint)
ownerLock := &nockchain.NockchainLock{
KeysRequired: 1,
Pubkeys: []string{crypto.Tip5HashToBase58(pkHash)},
}
childKeyScan, err := h.client.WalletGetBalance(&nockchain.GetBalanceRequest{
Selector: &nockchain.GetBalanceRequest_Address{
Address: address,
},
})
ownerHash := HashLock(ownerLock)
var scanReq *nockchain.GetBalanceRequest
switch req.Version {
case 0:
scanReq = &nockchain.GetBalanceRequest{
Selector: &nockchain.GetBalanceRequest_Address{
Address: base58.Encode(childKey.PublicKey),
},
}
case 1:
firstName := crypto.Tip5RehashTenCell(crypto.Tip5Zero, ownerHash)
scanReq = &nockchain.GetBalanceRequest{
Selector: &nockchain.GetBalanceRequest_FirstName{
FirstName: crypto.Tip5HashToBase58(firstName),
},
}
default:
return nil, fmt.Errorf("unsuport version")
}
childKeyScan, err := h.client.WalletGetBalance(scanReq)
if err != nil {
continue
}