Skip to content

add GetTaddressTransactions, label GetTaddressTxids deprecated #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/rtd/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,15 @@ <h3 id="cash.z.wallet.sdk.rpc.CompactTxStreamer">CompactTxStreamer</h3>
<td><a href="#cash.z.wallet.sdk.rpc.TransparentAddressBlockFilter">TransparentAddressBlockFilter</a></td>
<td><a href="#cash.z.wallet.sdk.rpc.RawTransaction">RawTransaction</a> stream</td>
<td><p>Return the transactions corresponding to the given t-address within the given block range
NB - this method is misnamed, it returns transactions, not transaction IDs.</p></td>
NB - this method is misnamed, it returns transactions, not transaction IDs.
NOTE: this method is deprecated, please use GetTaddressTransactions instead.</p></td>
</tr>

<tr>
<td>GetTaddressTransactions</td>
<td><a href="#cash.z.wallet.sdk.rpc.TransparentAddressBlockFilter">TransparentAddressBlockFilter</a></td>
<td><a href="#cash.z.wallet.sdk.rpc.RawTransaction">RawTransaction</a> stream</td>
<td><p>Return the transactions corresponding to the given t-address within the given block range</p></td>
</tr>

<tr>
Expand Down
28 changes: 14 additions & 14 deletions frontend/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestMain(m *testing.M) {
}

func TestGetTransaction(t *testing.T) {
// GetTransaction() will mostly be tested below via TestGetTaddressTxids
// GetTransaction() will mostly be tested below via TestGetTaddressTransactions
lwd, _ := testsetup()

rawtx, err := lwd.GetTransaction(context.Background(),
Expand Down Expand Up @@ -267,7 +267,7 @@ func zcashdrpcStub(method string, params []json.RawMessage) (json.RawMessage, er
}

type testgettx struct {
walletrpc.CompactTxStreamer_GetTaddressTxidsServer
walletrpc.CompactTxStreamer_GetTaddressTransactionsServer
}

func (tg *testgettx) Context() context.Context {
Expand All @@ -284,7 +284,7 @@ func (tg *testgettx) Send(tx *walletrpc.RawTransaction) error {
return nil
}

func TestGetTaddressTxids(t *testing.T) {
func TestGetTaddressTransactions(t *testing.T) {
testT = t
common.RawRequest = zcashdrpcStub
lwd, _ := testsetup()
Expand All @@ -299,38 +299,38 @@ func TestGetTaddressTxids(t *testing.T) {
// Ensure that a bad address is detected
for i, addressTest := range addressTests {
addressBlockFilter.Address = addressTest
err := lwd.GetTaddressTxids(addressBlockFilter, &testgettx{})
err := lwd.GetTaddressTransactions(addressBlockFilter, &testgettx{})
if err == nil {
t.Fatal("GetTaddressTxids should have failed on bad address, case", i)
t.Fatal("GetTaddressTransactions should have failed on bad address, case", i)
}
if !strings.Contains(err.Error(), "invalid characters") {
t.Fatal("GetTaddressTxids incorrect error on bad address, case", i)
t.Fatal("GetTaddressTransactions incorrect error on bad address, case", i)
}
}

// valid address
addressBlockFilter.Address = "t1234567890123456789012345678901234"
err := lwd.GetTaddressTxids(addressBlockFilter, &testgettx{})
err := lwd.GetTaddressTransactions(addressBlockFilter, &testgettx{})
if err != nil {
t.Fatal("GetTaddressTxids failed", err)
t.Fatal("GetTaddressTransactions failed", err)
}

// this time GetTransaction() will return an error
err = lwd.GetTaddressTxids(addressBlockFilter, &testgettx{})
err = lwd.GetTaddressTransactions(addressBlockFilter, &testgettx{})
if err == nil {
t.Fatal("GetTaddressTxids succeeded")
t.Fatal("GetTaddressTransactions succeeded")
}
step = 0
}

func TestGetTaddressTxidsNilArgs(t *testing.T) {
func TestGetTaddressTransactionsNilArgs(t *testing.T) {
lwd, _ := testsetup()

{
noRange := &walletrpc.TransparentAddressBlockFilter{
Range: nil,
}
err := lwd.GetTaddressTxids(noRange, &testgettx{})
err := lwd.GetTaddressTransactions(noRange, &testgettx{})
if err == nil {
t.Fatal("GetBlockRange nil range argument should fail")
}
Expand All @@ -342,7 +342,7 @@ func TestGetTaddressTxidsNilArgs(t *testing.T) {
End: &walletrpc.BlockID{Height: 20},
},
}
err := lwd.GetTaddressTxids(noStart, &testgettx{})
err := lwd.GetTaddressTransactions(noStart, &testgettx{})
if err == nil {
t.Fatal("GetBlockRange nil range argument should fail")
}
Expand All @@ -354,7 +354,7 @@ func TestGetTaddressTxidsNilArgs(t *testing.T) {
End: nil,
},
}
err := lwd.GetTaddressTxids(noEnd, &testgettx{})
err := lwd.GetTaddressTransactions(noEnd, &testgettx{})
if err == nil {
t.Fatal("GetBlockRange nil range argument should fail")
}
Expand Down
20 changes: 14 additions & 6 deletions frontend/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ func (s *lwdStreamer) GetLatestBlock(ctx context.Context, placeholder *walletrpc
// GetTaddressTxids is a streaming RPC that returns transactions that have
// the given transparent address (taddr) as either an input or output.
// NB, this method is misnamed, it does not return txids.
func (s *lwdStreamer) GetTaddressTxids(addressBlockFilter *walletrpc.TransparentAddressBlockFilter, resp walletrpc.CompactTxStreamer_GetTaddressTxidsServer) error {
common.Log.Debugf("gRPC GetTaddressTxids(%+v)\n", addressBlockFilter)
func (s *lwdStreamer) GetTaddressTransactions(addressBlockFilter *walletrpc.TransparentAddressBlockFilter, resp walletrpc.CompactTxStreamer_GetTaddressTransactionsServer) error {
common.Log.Debugf("gRPC GetTaddressTransactions(%+v)\n", addressBlockFilter)
if err := checkTaddress(addressBlockFilter.Address); err != nil {
// This returns a gRPC-compatible error.
return err
}

if addressBlockFilter.Range == nil {
return status.Error(codes.InvalidArgument, "GetTaddressTxids: must specify block range")
return status.Error(codes.InvalidArgument, "GetTaddressTransactions: must specify block range")
}
if addressBlockFilter.Range.Start == nil {
return status.Error(codes.InvalidArgument, "GetTaddressTxids: must specify a start block height")
return status.Error(codes.InvalidArgument, "GetTaddressTransactions: must specify a start block height")
}

request := &common.ZcashdRpcRequestGetaddresstxids{
Expand All @@ -116,7 +116,7 @@ func (s *lwdStreamer) GetTaddressTxids(addressBlockFilter *walletrpc.Transparent
param, err := json.Marshal(request)
if err != nil {
return status.Errorf(codes.InvalidArgument,
"GetTaddressTxids: error marshalling request: %s", err.Error())
"GetTaddressTransactions: error marshalling request: %s", err.Error())
}
params := []json.RawMessage{param}

Expand All @@ -125,7 +125,7 @@ func (s *lwdStreamer) GetTaddressTxids(addressBlockFilter *walletrpc.Transparent
// For some reason, the error responses are not JSON
if rpcErr != nil {
return status.Errorf(codes.InvalidArgument,
"GetTaddressTxids: getaddresstxids failed, error: %s", rpcErr.Error())
"GetTaddressTransactions: getaddresstxids failed, error: %s", rpcErr.Error())
}

var txids []string
Expand Down Expand Up @@ -153,6 +153,14 @@ func (s *lwdStreamer) GetTaddressTxids(addressBlockFilter *walletrpc.Transparent
return nil
}

// This method is deprecated; use GetTaddressTransactions instead. The two functions have the
// same functionality, but the name GetTaddressTxids is misleading, because the method returns
// transactions, not transaction IDs (txids). See https://github.com/zcash/lightwalletd/issues/426
func (s *lwdStreamer) GetTaddressTxids(addressBlockFilter *walletrpc.TransparentAddressBlockFilter, resp walletrpc.CompactTxStreamer_GetTaddressTxidsServer) error {
common.Log.Debugf("gRPC GetTaddressTxids, deprecated, calling GetTaddressTransactions...\n")
return s.GetTaddressTransactions(addressBlockFilter, resp)
}

// GetBlock returns the compact block at the requested height. Requesting a
// block by hash is not yet supported.
func (s *lwdStreamer) GetBlock(ctx context.Context, id *walletrpc.BlockID) (*walletrpc.CompactBlock, error) {
Expand Down
Loading