diff --git a/wallet/service.go b/wallet/service.go index 1b22543..97888a5 100644 --- a/wallet/service.go +++ b/wallet/service.go @@ -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 }