diff --git a/tx/go.mod b/tx/go.mod index c2543cbbbafc..89517623f115 100644 --- a/tx/go.mod +++ b/tx/go.mod @@ -13,9 +13,15 @@ require ( require ( github.com/cosmos/gogoproto v1.4.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/golang/protobuf v1.5.2 // indirect github.com/kr/pretty v0.3.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.8.1 // indirect + golang.org/x/net v0.0.0-20220726230323-06994584191e // indirect + golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect + golang.org/x/text v0.3.7 // indirect + google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b // indirect + google.golang.org/grpc v1.49.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/tx/go.sum b/tx/go.sum index 51da2f7c5b66..3c7ca9cffa3a 100644 --- a/tx/go.sum +++ b/tx/go.sum @@ -11,6 +11,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= @@ -34,8 +36,19 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +golang.org/x/net v0.0.0-20220726230323-06994584191e h1:wOQNKh1uuDGRnmgF0jDxh7ctgGy/3P4rYWQRVJD4/Yg= +golang.org/x/net v0.0.0-20220726230323-06994584191e/go.mod h1:AaygXjzTFtRAg2ttMY5RMuhpJ3cNnI0XpyFJD1iQRSM= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b h1:SfSkJugek6xm7lWywqth4r2iTrYLpD8lOj1nMIIhMNM= +google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= +google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw= +google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/tx/textual/internal/testdata/coin.json b/tx/textual/internal/testdata/coin.json new file mode 100644 index 000000000000..68a5fc37b900 --- /dev/null +++ b/tx/textual/internal/testdata/coin.json @@ -0,0 +1,357 @@ +[ + { + "proto": {"amount": "0", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0 COSM" + }, + { + "proto": {"amount": "1", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0.000001 COSM" + }, + { + "proto": {"amount": "10", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0.00001 COSM" + }, + { + "proto": {"amount": "100", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0.0001 COSM" + }, + { + "proto": {"amount": "1000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0.001 COSM" + }, + { + "proto": {"amount": "10000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0.01 COSM" + }, + { + "proto": {"amount": "100000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0.1 COSM" + }, + { + "proto": {"amount": "1000000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "1 COSM" + }, + { + "proto": {"amount": "10000000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "10 COSM" + }, + { + "proto": {"amount": "0", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}, {"denom":"stake", "exponent": 0}]}, + "text": "0 COSM" + }, + { + "proto": {"amount": "1", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}, {"denom":"stake", "exponent": 0}]}, + "text": "0.000001 COSM" + }, + { + "proto": {"amount": "10", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}, {"denom":"stake", "exponent": 0}]}, + "text": "0.00001 COSM" + }, + { + "proto": {"amount": "100", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}, {"denom":"stake", "exponent": 0}]}, + "text": "0.0001 COSM" + }, + { + "proto": {"amount": "1000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}, {"denom":"stake", "exponent": 0}]}, + "text": "0.001 COSM" + }, + { + "proto": {"amount": "10000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}, {"denom":"stake", "exponent": 0}]}, + "text": "0.01 COSM" + }, + { + "proto": {"amount": "100000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}, {"denom":"stake", "exponent": 0}]}, + "text": "0.1 COSM" + }, + { + "proto": {"amount": "1000000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}, {"denom":"stake", "exponent": 0}]}, + "text": "1 COSM" + }, + { + "proto": {"amount": "10000000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}, {"denom":"stake", "exponent": 0}]}, + "text": "10 COSM" + }, + { + "proto": {"amount": "0", "denom": "COSM"}, + "metadata": {"display": "ucosm", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0 ucosm" + }, + { + "proto": {"amount": "0.000001", "denom": "COSM"}, + "metadata": {"display": "ucosm", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "1 ucosm" + }, + { + "proto": {"amount": "0.00001", "denom": "COSM"}, + "metadata": {"display": "ucosm", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "10 ucosm" + }, + { + "proto": {"amount": "0.0001", "denom": "COSM"}, + "metadata": {"display": "ucosm", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "100 ucosm" + }, + { + "proto": {"amount": "0.001", "denom": "COSM"}, + "metadata": {"display": "ucosm", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "1'000 ucosm" + }, + { + "proto": {"amount": "0.01", "denom": "COSM"}, + "metadata": {"display": "ucosm", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "10'000 ucosm" + }, + { + "proto": {"amount": "0.1", "denom": "COSM"}, + "metadata": {"display": "ucosm", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "100'000 ucosm" + }, + { + "proto": {"amount": "1", "denom": "COSM"}, + "metadata": {"display": "ucosm", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "1'000'000 ucosm" + }, + { + "proto": {"amount": "10", "denom": "COSM"}, + "metadata": {"display": "ucosm", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "10'000'000 ucosm" + }, + { + "proto": {"amount": "0", "denom": "ucosm"}, + "metadata": {"denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0 ucosm" + }, + { + "proto": {"amount": "1", "denom": "ucosm"}, + "metadata": {"denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "1 ucosm" + }, + { + "proto": {"amount": "10", "denom": "ucosm"}, + "metadata": {"denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "10 ucosm" + }, + { + "proto": {"amount": "100", "denom": "ucosm"}, + "metadata": {"denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "100 ucosm" + }, + { + "proto": {"amount": "1000", "denom": "ucosm"}, + "metadata": {"denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "1'000 ucosm" + }, + { + "proto": {"amount": "10000", "denom": "ucosm"}, + "metadata": {"denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "10'000 ucosm" + }, + { + "proto": {"amount": "100000", "denom": "ucosm"}, + "metadata": {"denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "100'000 ucosm" + }, + { + "proto": {"amount": "1000000", "denom": "ucosm"}, + "metadata": {"denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "1'000'000 ucosm" + }, + { + "proto": {"amount": "10000000", "denom": "ucosm"}, + "metadata": {"denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "text": "10'000'000 ucosm" + }, + { + "proto": {"amount": "0", "denom": "ucosm"}, + "text": "0 ucosm" + }, + { + "proto": {"amount": "1", "denom": "ucosm"}, + "text": "1 ucosm" + }, + { + "proto": {"amount": "10", "denom": "ucosm"}, + "text": "10 ucosm" + }, + { + "proto": {"amount": "100", "denom": "ucosm"}, + "text": "100 ucosm" + }, + { + "proto": {"amount": "1000", "denom": "ucosm"}, + "text": "1'000 ucosm" + }, + { + "proto": {"amount": "10000", "denom": "ucosm"}, + "text": "10'000 ucosm" + }, + { + "proto": {"amount": "100000", "denom": "ucosm"}, + "text": "100'000 ucosm" + }, + { + "proto": {"amount": "1000000", "denom": "ucosm"}, + "text": "1'000'000 ucosm" + }, + { + "proto": {"amount": "10000000", "denom": "ucosm"}, + "text": "10'000'000 ucosm" + }, + { + "proto": {"amount": "0", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}]}, + "text": "0 ucosm" + }, + { + "proto": {"amount": "1", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}]}, + "text": "1 ucosm" + }, + { + "proto": {"amount": "10", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}]}, + "text": "10 ucosm" + }, + { + "proto": {"amount": "100", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}]}, + "text": "100 ucosm" + }, + { + "proto": {"amount": "1000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}]}, + "text": "1'000 ucosm" + }, + { + "proto": {"amount": "10000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}]}, + "text": "10'000 ucosm" + }, + { + "proto": {"amount": "100000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}]}, + "text": "100'000 ucosm" + }, + { + "proto": {"amount": "1000000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}]}, + "text": "1'000'000 ucosm" + }, + { + "proto": {"amount": "10000000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}]}, + "text": "10'000'000 ucosm" + }, + { + "proto": {"amount": "0", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0 COSM" + }, + { + "proto": {"amount": "1", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0.01 COSM" + }, + { + "proto": {"amount": "10", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}, {"denom": "ucosm", "exponent": 0}]}, + "text": "0.1 COSM" + }, + { + "proto": {"amount": "100", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}, {"denom": "ucosm", "exponent": 0}]}, + "text": "1 COSM" + }, + { + "proto": {"amount": "1000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}, {"denom": "ucosm", "exponent": 0}]}, + "text": "10 COSM" + }, + { + "proto": {"amount": "10000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}, {"denom": "ucosm", "exponent": 0}]}, + "text": "100 COSM" + }, + { + "proto": {"amount": "100000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}, {"denom": "ucosm", "exponent": 0}]}, + "text": "1'000 COSM" + }, + { + "proto": {"amount": "1000000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}, {"denom": "ucosm", "exponent": 0}]}, + "text": "10'000 COSM" + }, + { + "proto": {"amount": "10000000", "denom": "ucosm"}, + "metadata": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 2}, {"denom": "ucosm", "exponent": 0}]}, + "text": "100'000 COSM" + }, + { + "proto": {"amount": "0", "denom": "point"}, + "metadata": {"display": "POINT", "denom_units": [{"denom": "point", "exponent": 0}, {"denom": "POINT", "exponent": 0}]}, + "text": "0 POINT" + }, + { + "proto": {"amount": "1", "denom": "point"}, + "metadata": {"display": "POINT", "denom_units": [{"denom": "point", "exponent": 0}, {"denom": "POINT", "exponent": 0}]}, + "text": "1 POINT" + }, + { + "proto": {"amount": "10", "denom": "point"}, + "metadata": {"display": "POINT", "denom_units": [{"denom": "point", "exponent": 0}, {"denom": "POINT", "exponent": 0}]}, + "text": "10 POINT" + }, + { + "proto": {"amount": "100", "denom": "point"}, + "metadata": {"display": "POINT", "denom_units": [{"denom": "point", "exponent": 0}, {"denom": "POINT", "exponent": 0}]}, + "text": "100 POINT" + }, + { + "proto": {"amount": "1000", "denom": "point"}, + "metadata": {"display": "POINT", "denom_units": [{"denom": "point", "exponent": 0}, {"denom": "POINT", "exponent": 0}]}, + "text": "1'000 POINT" + }, + { + "proto": {"amount": "10000", "denom": "point"}, + "metadata": {"display": "POINT", "denom_units": [{"denom": "point", "exponent": 0}, {"denom": "POINT", "exponent": 0}]}, + "text": "10'000 POINT" + }, + { + "proto": {"amount": "100000", "denom": "point"}, + "metadata": {"display": "POINT", "denom_units": [{"denom": "point", "exponent": 0}, {"denom": "POINT", "exponent": 0}]}, + "text": "100'000 POINT" + }, + { + "proto": {"amount": "1000000", "denom": "point"}, + "metadata": {"display": "POINT", "denom_units": [{"denom": "point", "exponent": 0}, {"denom": "POINT", "exponent": 0}]}, + "text": "1'000'000 POINT" + }, + { + "proto": {"amount": "10000000", "denom": "point"}, + "metadata": {"display": "POINT", "denom_units": [{"denom": "point", "exponent": 0}, {"denom": "POINT", "exponent": 0}]}, + "text": "10'000'000 POINT" + }, + {"text":"", "error": true}, + {"text":"1COSM", "error": true}, + {"text":"1 COSM", "error": true}, + {"text":" 1 COSM", "error": true} +] diff --git a/tx/textual/internal/testdata/coins.json b/tx/textual/internal/testdata/coins.json new file mode 100644 index 000000000000..ccac405411bb --- /dev/null +++ b/tx/textual/internal/testdata/coins.json @@ -0,0 +1,72 @@ +[ + { + "proto": [], + "metadata":{}, + "text": "" + }, + { + "proto": [ + { "amount": "1", "denom": "ucosm" } + ], + "metadata":{ + "ucosm": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "ustake": {"display": "STAKE", "denom_units": [{"denom": "STAKE", "exponent": 6}, {"denom": "ustake", "exponent": 0}]} + }, + "text": "0.000001 COSM" + }, + { + "proto": [ + { "amount": "1", "denom": "ucosm" }, + { "amount": "3", "denom": "ustake" } + ], + "metadata":{ + "ucosm": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "ustake": {"display": "STAKE", "denom_units": [{"denom": "STAKE", "exponent": 6}, {"denom": "ustake", "exponent": 0}]} + }, + "text": "0.000001 COSM, 0.000003 STAKE" + }, + { + "proto": [ + { "amount": "3", "denom": "ustake" }, + { "amount": "1", "denom": "ucosm" } + ], + "metadata": { + "ucosm": {"display": "COSM", "denom_units": [{"denom": "COSM", "exponent": 6}, {"denom": "ucosm", "exponent": 0}]}, + "ustake": {"display": "STAKE", "denom_units": [{"denom": "STAKE", "exponent": 6}, {"denom": "ustake", "exponent": 0}]} + }, + "text": "0.000001 COSM, 0.000003 STAKE" + }, + { + "proto": [ + { "amount": "1", "denom": "uaa" }, + { "amount": "2", "denom": "ubb" }, + { "amount": "3", "denom": "uatom" } + ], + "metadata": { + "uaa": {"display": "AA", "denom_units": [{"denom": "AA", "exponent": 6}, {"denom": "uaa", "exponent": 0}]}, + "ubb": {"display": "BB", "denom_units": [{"denom": "BB", "exponent": 6}, {"denom": "ubb", "exponent": 0}]}, + "uatom": {"display": "atom", "denom_units": [{"denom": "atom", "exponent": 6}, {"denom": "uatom", "exponent": 0}]} + }, + "text": "0.000001 AA, 0.000002 BB, 0.000003 atom" + }, + { + "proto": [ + { "amount": "4", "denom": "uxc1" }, + { "amount": "3", "denom": "uxc" }, + { "amount": "2", "denom": "uxb" }, + { "amount": "1", "denom": "uxa" } + ], + "metadata": { + "uxa": {"display": "xA", "denom_units": [{"denom": "xA", "exponent": 6}, {"denom": "uxa", "exponent": 0}]}, + "uxb": {"display": "xB", "denom_units": [{"denom": "xB", "exponent": 6}, {"denom": "uxb", "exponent": 0}]}, + "uxc": {"display": "xC", "denom_units": [{"denom": "xC", "exponent": 6}, {"denom": "uxc", "exponent": 0}]}, + "uxc1": {"display": "xC1", "denom_units": [{"denom": "xC1", "exponent": 6}, {"denom": "uxc1", "exponent": 0}]} + }, + "text": "0.000001 xA, 0.000002 xB, 0.000003 xC, 0.000004 xC1" + }, + {"text": "0.000001AA, 0.000002 BB, 0.000003 atom", "error": true}, + {"text": "0.000001 AA, 0.000002 BB, 0.000003 atom", "error": true}, + {"text": "0.000001 AA, 0.000002 BB, 0.000003 atom", "error": true}, + {"text": " 0.000001 AA, 0.000002 BB, 0.000003 atom", "error": true}, + {"text": "0.000001 AA, 0.000002 BB, 0.000003 atom ", "error": true} +] diff --git a/tx/textual/internal/testpb/1.proto b/tx/textual/internal/testpb/1.proto index bc6030e45d85..43c73dfd37c5 100644 --- a/tx/textual/internal/testpb/1.proto +++ b/tx/textual/internal/testpb/1.proto @@ -12,32 +12,28 @@ enum Enumeration { Two = 1; } -// A contains fields that are parseable by SIGN_MODE_TEXTUAL. +// A is used for testing value renderers. message A { - uint32 UINT32 = 1; - uint64 UINT64 = 2; - int32 INT32 = 3; - int64 INT64 = 4; - string SDKINT = 5 [(cosmos_proto.scalar) = "cosmos.Int"]; - string SDKDEC = 6 [(cosmos_proto.scalar) = "cosmos.Dec"]; - cosmos.base.v1beta1.Coin COIN = 7; - repeated cosmos.base.v1beta1.Coin COINS = 8; - bytes BYTES = 9; - google.protobuf.Timestamp TIMESTAMP = 10; -} + // Fields that are parseable by SIGN_MODE_TEXTUAL. + uint32 UINT32 = 1; + uint64 UINT64 = 2; + int32 INT32 = 3; + int64 INT64 = 4; + string SDKINT = 5 [(cosmos_proto.scalar) = "cosmos.Int"]; + string SDKDEC = 6 [(cosmos_proto.scalar) = "cosmos.Dec"]; + cosmos.base.v1beta1.Coin COIN = 7; + repeated cosmos.base.v1beta1.Coin COINS = 8; + bytes BYTES = 9; + google.protobuf.Timestamp TIMESTAMP = 10; -// B contains fields that are not parseable by SIGN_MODE_TEXTUAL, some fields -// may be moved to A at some point. -message B { - int32 INT32 = 1; - sint32 SINT32 = 2; - int64 INT64 = 3; - sint64 SING64 = 4; - sfixed32 SFIXED32 = 5; - fixed32 FIXED32 = 6; - float FLOAT = 7; - sfixed64 SFIXED64 = 8; - fixed64 FIXED64 = 9; - double DOUBLE = 10; - map MAP = 11; + // Fields that are not handled by SIGN_MODE_TEXTUAL. + sint32 SINT32 = 101; + sint64 SINT64 = 102; + sfixed32 SFIXED32 = 105; + fixed32 FIXED32 = 106; + float FLOAT = 107; + sfixed64 SFIXED64 = 108; + fixed64 FIXED64 = 109; + double DOUBLE = 110; + map MAP = 111; } diff --git a/tx/textual/internal/testpb/1.pulsar.go b/tx/textual/internal/testpb/1.pulsar.go index 2bfa686ad1fb..ec0a5943b035 100644 --- a/tx/textual/internal/testpb/1.pulsar.go +++ b/tx/textual/internal/testpb/1.pulsar.go @@ -70,6 +70,96 @@ func (x *_A_8_list) IsValid() bool { return x.list != nil } +var _ protoreflect.Map = (*_A_111_map)(nil) + +type _A_111_map struct { + m *map[string]*A +} + +func (x *_A_111_map) Len() int { + if x.m == nil { + return 0 + } + return len(*x.m) +} + +func (x *_A_111_map) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) { + if x.m == nil { + return + } + for k, v := range *x.m { + mapKey := (protoreflect.MapKey)(protoreflect.ValueOfString(k)) + mapValue := protoreflect.ValueOfMessage(v.ProtoReflect()) + if !f(mapKey, mapValue) { + break + } + } +} + +func (x *_A_111_map) Has(key protoreflect.MapKey) bool { + if x.m == nil { + return false + } + keyUnwrapped := key.String() + concreteValue := keyUnwrapped + _, ok := (*x.m)[concreteValue] + return ok +} + +func (x *_A_111_map) Clear(key protoreflect.MapKey) { + if x.m == nil { + return + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + delete(*x.m, concreteKey) +} + +func (x *_A_111_map) Get(key protoreflect.MapKey) protoreflect.Value { + if x.m == nil { + return protoreflect.Value{} + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + v, ok := (*x.m)[concreteKey] + if !ok { + return protoreflect.Value{} + } + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_A_111_map) Set(key protoreflect.MapKey, value protoreflect.Value) { + if !key.IsValid() || !value.IsValid() { + panic("invalid key or value provided") + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*A) + (*x.m)[concreteKey] = concreteValue +} + +func (x *_A_111_map) Mutable(key protoreflect.MapKey) protoreflect.Value { + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + v, ok := (*x.m)[concreteKey] + if ok { + return protoreflect.ValueOfMessage(v.ProtoReflect()) + } + newValue := new(A) + (*x.m)[concreteKey] = newValue + return protoreflect.ValueOfMessage(newValue.ProtoReflect()) +} + +func (x *_A_111_map) NewValue() protoreflect.Value { + v := new(A) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_A_111_map) IsValid() bool { + return x.m != nil +} + var ( md_A protoreflect.MessageDescriptor fd_A_UINT32 protoreflect.FieldDescriptor @@ -82,6 +172,15 @@ var ( fd_A_COINS protoreflect.FieldDescriptor fd_A_BYTES protoreflect.FieldDescriptor fd_A_TIMESTAMP protoreflect.FieldDescriptor + fd_A_SINT32 protoreflect.FieldDescriptor + fd_A_SINT64 protoreflect.FieldDescriptor + fd_A_SFIXED32 protoreflect.FieldDescriptor + fd_A_FIXED32 protoreflect.FieldDescriptor + fd_A_FLOAT protoreflect.FieldDescriptor + fd_A_SFIXED64 protoreflect.FieldDescriptor + fd_A_FIXED64 protoreflect.FieldDescriptor + fd_A_DOUBLE protoreflect.FieldDescriptor + fd_A_MAP protoreflect.FieldDescriptor ) func init() { @@ -97,6 +196,15 @@ func init() { fd_A_COINS = md_A.Fields().ByName("COINS") fd_A_BYTES = md_A.Fields().ByName("BYTES") fd_A_TIMESTAMP = md_A.Fields().ByName("TIMESTAMP") + fd_A_SINT32 = md_A.Fields().ByName("SINT32") + fd_A_SINT64 = md_A.Fields().ByName("SINT64") + fd_A_SFIXED32 = md_A.Fields().ByName("SFIXED32") + fd_A_FIXED32 = md_A.Fields().ByName("FIXED32") + fd_A_FLOAT = md_A.Fields().ByName("FLOAT") + fd_A_SFIXED64 = md_A.Fields().ByName("SFIXED64") + fd_A_FIXED64 = md_A.Fields().ByName("FIXED64") + fd_A_DOUBLE = md_A.Fields().ByName("DOUBLE") + fd_A_MAP = md_A.Fields().ByName("MAP") } var _ protoreflect.Message = (*fastReflection_A)(nil) @@ -224,6 +332,60 @@ func (x *fastReflection_A) Range(f func(protoreflect.FieldDescriptor, protorefle return } } + if x.SINT32 != int32(0) { + value := protoreflect.ValueOfInt32(x.SINT32) + if !f(fd_A_SINT32, value) { + return + } + } + if x.SINT64 != int64(0) { + value := protoreflect.ValueOfInt64(x.SINT64) + if !f(fd_A_SINT64, value) { + return + } + } + if x.SFIXED32 != int32(0) { + value := protoreflect.ValueOfInt32(x.SFIXED32) + if !f(fd_A_SFIXED32, value) { + return + } + } + if x.FIXED32 != uint32(0) { + value := protoreflect.ValueOfUint32(x.FIXED32) + if !f(fd_A_FIXED32, value) { + return + } + } + if x.FLOAT != float32(0) || math.Signbit(float64(x.FLOAT)) { + value := protoreflect.ValueOfFloat32(x.FLOAT) + if !f(fd_A_FLOAT, value) { + return + } + } + if x.SFIXED64 != int64(0) { + value := protoreflect.ValueOfInt64(x.SFIXED64) + if !f(fd_A_SFIXED64, value) { + return + } + } + if x.FIXED64 != uint64(0) { + value := protoreflect.ValueOfUint64(x.FIXED64) + if !f(fd_A_FIXED64, value) { + return + } + } + if x.DOUBLE != float64(0) || math.Signbit(x.DOUBLE) { + value := protoreflect.ValueOfFloat64(x.DOUBLE) + if !f(fd_A_DOUBLE, value) { + return + } + } + if len(x.MAP) != 0 { + value := protoreflect.ValueOfMap(&_A_111_map{m: &x.MAP}) + if !f(fd_A_MAP, value) { + return + } + } } // Has reports whether a field is populated. @@ -259,6 +421,24 @@ func (x *fastReflection_A) Has(fd protoreflect.FieldDescriptor) bool { return len(x.BYTES) != 0 case "A.TIMESTAMP": return x.TIMESTAMP != nil + case "A.SINT32": + return x.SINT32 != int32(0) + case "A.SINT64": + return x.SINT64 != int64(0) + case "A.SFIXED32": + return x.SFIXED32 != int32(0) + case "A.FIXED32": + return x.FIXED32 != uint32(0) + case "A.FLOAT": + return x.FLOAT != float32(0) || math.Signbit(float64(x.FLOAT)) + case "A.SFIXED64": + return x.SFIXED64 != int64(0) + case "A.FIXED64": + return x.FIXED64 != uint64(0) + case "A.DOUBLE": + return x.DOUBLE != float64(0) || math.Signbit(x.DOUBLE) + case "A.MAP": + return len(x.MAP) != 0 default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: A")) @@ -295,6 +475,24 @@ func (x *fastReflection_A) Clear(fd protoreflect.FieldDescriptor) { x.BYTES = nil case "A.TIMESTAMP": x.TIMESTAMP = nil + case "A.SINT32": + x.SINT32 = int32(0) + case "A.SINT64": + x.SINT64 = int64(0) + case "A.SFIXED32": + x.SFIXED32 = int32(0) + case "A.FIXED32": + x.FIXED32 = uint32(0) + case "A.FLOAT": + x.FLOAT = float32(0) + case "A.SFIXED64": + x.SFIXED64 = int64(0) + case "A.FIXED64": + x.FIXED64 = uint64(0) + case "A.DOUBLE": + x.DOUBLE = float64(0) + case "A.MAP": + x.MAP = nil default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: A")) @@ -344,6 +542,36 @@ func (x *fastReflection_A) Get(descriptor protoreflect.FieldDescriptor) protoref case "A.TIMESTAMP": value := x.TIMESTAMP return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "A.SINT32": + value := x.SINT32 + return protoreflect.ValueOfInt32(value) + case "A.SINT64": + value := x.SINT64 + return protoreflect.ValueOfInt64(value) + case "A.SFIXED32": + value := x.SFIXED32 + return protoreflect.ValueOfInt32(value) + case "A.FIXED32": + value := x.FIXED32 + return protoreflect.ValueOfUint32(value) + case "A.FLOAT": + value := x.FLOAT + return protoreflect.ValueOfFloat32(value) + case "A.SFIXED64": + value := x.SFIXED64 + return protoreflect.ValueOfInt64(value) + case "A.FIXED64": + value := x.FIXED64 + return protoreflect.ValueOfUint64(value) + case "A.DOUBLE": + value := x.DOUBLE + return protoreflect.ValueOfFloat64(value) + case "A.MAP": + if len(x.MAP) == 0 { + return protoreflect.ValueOfMap(&_A_111_map{}) + } + mapValue := &_A_111_map{m: &x.MAP} + return protoreflect.ValueOfMap(mapValue) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: A")) @@ -386,6 +614,26 @@ func (x *fastReflection_A) Set(fd protoreflect.FieldDescriptor, value protorefle x.BYTES = value.Bytes() case "A.TIMESTAMP": x.TIMESTAMP = value.Message().Interface().(*timestamppb.Timestamp) + case "A.SINT32": + x.SINT32 = int32(value.Int()) + case "A.SINT64": + x.SINT64 = value.Int() + case "A.SFIXED32": + x.SFIXED32 = int32(value.Int()) + case "A.FIXED32": + x.FIXED32 = uint32(value.Uint()) + case "A.FLOAT": + x.FLOAT = float32(value.Float()) + case "A.SFIXED64": + x.SFIXED64 = value.Int() + case "A.FIXED64": + x.FIXED64 = value.Uint() + case "A.DOUBLE": + x.DOUBLE = value.Float() + case "A.MAP": + mv := value.Map() + cmv := mv.(*_A_111_map) + x.MAP = *cmv.m default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: A")) @@ -422,6 +670,12 @@ func (x *fastReflection_A) Mutable(fd protoreflect.FieldDescriptor) protoreflect x.TIMESTAMP = new(timestamppb.Timestamp) } return protoreflect.ValueOfMessage(x.TIMESTAMP.ProtoReflect()) + case "A.MAP": + if x.MAP == nil { + x.MAP = make(map[string]*A) + } + value := &_A_111_map{m: &x.MAP} + return protoreflect.ValueOfMap(value) case "A.UINT32": panic(fmt.Errorf("field UINT32 of message A is not mutable")) case "A.UINT64": @@ -436,6 +690,22 @@ func (x *fastReflection_A) Mutable(fd protoreflect.FieldDescriptor) protoreflect panic(fmt.Errorf("field SDKDEC of message A is not mutable")) case "A.BYTES": panic(fmt.Errorf("field BYTES of message A is not mutable")) + case "A.SINT32": + panic(fmt.Errorf("field SINT32 of message A is not mutable")) + case "A.SINT64": + panic(fmt.Errorf("field SINT64 of message A is not mutable")) + case "A.SFIXED32": + panic(fmt.Errorf("field SFIXED32 of message A is not mutable")) + case "A.FIXED32": + panic(fmt.Errorf("field FIXED32 of message A is not mutable")) + case "A.FLOAT": + panic(fmt.Errorf("field FLOAT of message A is not mutable")) + case "A.SFIXED64": + panic(fmt.Errorf("field SFIXED64 of message A is not mutable")) + case "A.FIXED64": + panic(fmt.Errorf("field FIXED64 of message A is not mutable")) + case "A.DOUBLE": + panic(fmt.Errorf("field DOUBLE of message A is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: A")) @@ -472,6 +742,25 @@ func (x *fastReflection_A) NewField(fd protoreflect.FieldDescriptor) protoreflec case "A.TIMESTAMP": m := new(timestamppb.Timestamp) return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "A.SINT32": + return protoreflect.ValueOfInt32(int32(0)) + case "A.SINT64": + return protoreflect.ValueOfInt64(int64(0)) + case "A.SFIXED32": + return protoreflect.ValueOfInt32(int32(0)) + case "A.FIXED32": + return protoreflect.ValueOfUint32(uint32(0)) + case "A.FLOAT": + return protoreflect.ValueOfFloat32(float32(0)) + case "A.SFIXED64": + return protoreflect.ValueOfInt64(int64(0)) + case "A.FIXED64": + return protoreflect.ValueOfUint64(uint64(0)) + case "A.DOUBLE": + return protoreflect.ValueOfFloat64(float64(0)) + case "A.MAP": + m := make(map[string]*A) + return protoreflect.ValueOfMap(&_A_111_map{m: &m}) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: A")) @@ -579,6 +868,56 @@ func (x *fastReflection_A) ProtoMethods() *protoiface.Methods { l = options.Size(x.TIMESTAMP) n += 1 + l + runtime.Sov(uint64(l)) } + if x.SINT32 != 0 { + n += 2 + runtime.Soz(uint64(x.SINT32)) + } + if x.SINT64 != 0 { + n += 2 + runtime.Soz(uint64(x.SINT64)) + } + if x.SFIXED32 != 0 { + n += 6 + } + if x.FIXED32 != 0 { + n += 6 + } + if x.FLOAT != 0 || math.Signbit(float64(x.FLOAT)) { + n += 6 + } + if x.SFIXED64 != 0 { + n += 10 + } + if x.FIXED64 != 0 { + n += 10 + } + if x.DOUBLE != 0 || math.Signbit(x.DOUBLE) { + n += 10 + } + if len(x.MAP) > 0 { + SiZeMaP := func(k string, v *A) { + l := 0 + if v != nil { + l = options.Size(v) + } + l += 1 + runtime.Sov(uint64(l)) + mapEntrySize := 1 + len(k) + runtime.Sov(uint64(len(k))) + l + n += mapEntrySize + 2 + runtime.Sov(uint64(mapEntrySize)) + } + if options.Deterministic { + sortme := make([]string, 0, len(x.MAP)) + for k := range x.MAP { + sortme = append(sortme, k) + } + sort.Strings(sortme) + for _, k := range sortme { + v := x.MAP[k] + SiZeMaP(k, v) + } + } else { + for k, v := range x.MAP { + SiZeMaP(k, v) + } + } + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -608,30 +947,10 @@ func (x *fastReflection_A) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } - if x.TIMESTAMP != nil { - encoded, err := options.Marshal(x.TIMESTAMP) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x52 - } - if len(x.BYTES) > 0 { - i -= len(x.BYTES) - copy(dAtA[i:], x.BYTES) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.BYTES))) - i-- - dAtA[i] = 0x4a - } - if len(x.COINS) > 0 { - for iNdEx := len(x.COINS) - 1; iNdEx >= 0; iNdEx-- { - encoded, err := options.Marshal(x.COINS[iNdEx]) + if len(x.MAP) > 0 { + MaRsHaLmAp := func(k string, v *A) (protoiface.MarshalOutput, error) { + baseI := i + encoded, err := options.Marshal(v) if err != nil { return protoiface.MarshalOutput{ NoUnkeyedLiterals: input.NoUnkeyedLiterals, @@ -642,16 +961,150 @@ func (x *fastReflection_A) ProtoMethods() *protoiface.Methods { copy(dAtA[i:], encoded) i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) i-- - dAtA[i] = 0x42 + dAtA[i] = 0x12 + i -= len(k) + copy(dAtA[i:], k) + i = runtime.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = runtime.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x6 + i-- + dAtA[i] = 0xfa + return protoiface.MarshalOutput{}, nil } - } - if x.COIN != nil { - encoded, err := options.Marshal(x.COIN) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err + if options.Deterministic { + keysForMAP := make([]string, 0, len(x.MAP)) + for k := range x.MAP { + keysForMAP = append(keysForMAP, string(k)) + } + sort.Slice(keysForMAP, func(i, j int) bool { + return keysForMAP[i] < keysForMAP[j] + }) + for iNdEx := len(keysForMAP) - 1; iNdEx >= 0; iNdEx-- { + v := x.MAP[string(keysForMAP[iNdEx])] + out, err := MaRsHaLmAp(keysForMAP[iNdEx], v) + if err != nil { + return out, err + } + } + } else { + for k := range x.MAP { + v := x.MAP[k] + out, err := MaRsHaLmAp(k, v) + if err != nil { + return out, err + } + } + } + } + if x.DOUBLE != 0 || math.Signbit(x.DOUBLE) { + i -= 8 + binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(x.DOUBLE)))) + i-- + dAtA[i] = 0x6 + i-- + dAtA[i] = 0xf1 + } + if x.FIXED64 != 0 { + i -= 8 + binary.LittleEndian.PutUint64(dAtA[i:], uint64(x.FIXED64)) + i-- + dAtA[i] = 0x6 + i-- + dAtA[i] = 0xe9 + } + if x.SFIXED64 != 0 { + i -= 8 + binary.LittleEndian.PutUint64(dAtA[i:], uint64(x.SFIXED64)) + i-- + dAtA[i] = 0x6 + i-- + dAtA[i] = 0xe1 + } + if x.FLOAT != 0 || math.Signbit(float64(x.FLOAT)) { + i -= 4 + binary.LittleEndian.PutUint32(dAtA[i:], uint32(math.Float32bits(float32(x.FLOAT)))) + i-- + dAtA[i] = 0x6 + i-- + dAtA[i] = 0xdd + } + if x.FIXED32 != 0 { + i -= 4 + binary.LittleEndian.PutUint32(dAtA[i:], uint32(x.FIXED32)) + i-- + dAtA[i] = 0x6 + i-- + dAtA[i] = 0xd5 + } + if x.SFIXED32 != 0 { + i -= 4 + binary.LittleEndian.PutUint32(dAtA[i:], uint32(x.SFIXED32)) + i-- + dAtA[i] = 0x6 + i-- + dAtA[i] = 0xcd + } + if x.SINT64 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64((uint64(x.SINT64)<<1)^uint64((x.SINT64>>63)))) + i-- + dAtA[i] = 0x6 + i-- + dAtA[i] = 0xb0 + } + if x.SINT32 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64((uint32(x.SINT32)<<1)^uint32((x.SINT32>>31)))) + i-- + dAtA[i] = 0x6 + i-- + dAtA[i] = 0xa8 + } + if x.TIMESTAMP != nil { + encoded, err := options.Marshal(x.TIMESTAMP) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x52 + } + if len(x.BYTES) > 0 { + i -= len(x.BYTES) + copy(dAtA[i:], x.BYTES) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.BYTES))) + i-- + dAtA[i] = 0x4a + } + if len(x.COINS) > 0 { + for iNdEx := len(x.COINS) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.COINS[iNdEx]) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x42 + } + } + if x.COIN != nil { + encoded, err := options.Marshal(x.COIN) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err } i -= len(encoded) copy(dAtA[i:], encoded) @@ -894,988 +1347,69 @@ func (x *fastReflection_A) ProtoMethods() *protoiface.Methods { if iNdEx >= l { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.COIN == nil { - x.COIN = &v1beta1.Coin{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.COIN); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 8: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field COINS", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.COINS = append(x.COINS, &v1beta1.Coin{}) - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.COINS[len(x.COINS)-1]); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 9: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field BYTES", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.BYTES = append(x.BYTES[:0], dAtA[iNdEx:postIndex]...) - if x.BYTES == nil { - x.BYTES = []byte{} - } - iNdEx = postIndex - case 10: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field TIMESTAMP", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.TIMESTAMP == nil { - x.TIMESTAMP = ×tamppb.Timestamp{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.TIMESTAMP); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if !options.DiscardUnknown { - x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) - } - iNdEx += skippy - } - } - - if iNdEx > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil - } - return &protoiface.Methods{ - NoUnkeyedLiterals: struct{}{}, - Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, - Size: size, - Marshal: marshal, - Unmarshal: unmarshal, - Merge: nil, - CheckInitialized: nil, - } -} - -var _ protoreflect.Map = (*_B_11_map)(nil) - -type _B_11_map struct { - m *map[string]*B -} - -func (x *_B_11_map) Len() int { - if x.m == nil { - return 0 - } - return len(*x.m) -} - -func (x *_B_11_map) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) { - if x.m == nil { - return - } - for k, v := range *x.m { - mapKey := (protoreflect.MapKey)(protoreflect.ValueOfString(k)) - mapValue := protoreflect.ValueOfMessage(v.ProtoReflect()) - if !f(mapKey, mapValue) { - break - } - } -} - -func (x *_B_11_map) Has(key protoreflect.MapKey) bool { - if x.m == nil { - return false - } - keyUnwrapped := key.String() - concreteValue := keyUnwrapped - _, ok := (*x.m)[concreteValue] - return ok -} - -func (x *_B_11_map) Clear(key protoreflect.MapKey) { - if x.m == nil { - return - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - delete(*x.m, concreteKey) -} - -func (x *_B_11_map) Get(key protoreflect.MapKey) protoreflect.Value { - if x.m == nil { - return protoreflect.Value{} - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - v, ok := (*x.m)[concreteKey] - if !ok { - return protoreflect.Value{} - } - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_B_11_map) Set(key protoreflect.MapKey, value protoreflect.Value) { - if !key.IsValid() || !value.IsValid() { - panic("invalid key or value provided") - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*B) - (*x.m)[concreteKey] = concreteValue -} - -func (x *_B_11_map) Mutable(key protoreflect.MapKey) protoreflect.Value { - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - v, ok := (*x.m)[concreteKey] - if ok { - return protoreflect.ValueOfMessage(v.ProtoReflect()) - } - newValue := new(B) - (*x.m)[concreteKey] = newValue - return protoreflect.ValueOfMessage(newValue.ProtoReflect()) -} - -func (x *_B_11_map) NewValue() protoreflect.Value { - v := new(B) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_B_11_map) IsValid() bool { - return x.m != nil -} - -var ( - md_B protoreflect.MessageDescriptor - fd_B_INT32 protoreflect.FieldDescriptor - fd_B_SINT32 protoreflect.FieldDescriptor - fd_B_INT64 protoreflect.FieldDescriptor - fd_B_SING64 protoreflect.FieldDescriptor - fd_B_SFIXED32 protoreflect.FieldDescriptor - fd_B_FIXED32 protoreflect.FieldDescriptor - fd_B_FLOAT protoreflect.FieldDescriptor - fd_B_SFIXED64 protoreflect.FieldDescriptor - fd_B_FIXED64 protoreflect.FieldDescriptor - fd_B_DOUBLE protoreflect.FieldDescriptor - fd_B_MAP protoreflect.FieldDescriptor -) - -func init() { - file__1_proto_init() - md_B = File__1_proto.Messages().ByName("B") - fd_B_INT32 = md_B.Fields().ByName("INT32") - fd_B_SINT32 = md_B.Fields().ByName("SINT32") - fd_B_INT64 = md_B.Fields().ByName("INT64") - fd_B_SING64 = md_B.Fields().ByName("SING64") - fd_B_SFIXED32 = md_B.Fields().ByName("SFIXED32") - fd_B_FIXED32 = md_B.Fields().ByName("FIXED32") - fd_B_FLOAT = md_B.Fields().ByName("FLOAT") - fd_B_SFIXED64 = md_B.Fields().ByName("SFIXED64") - fd_B_FIXED64 = md_B.Fields().ByName("FIXED64") - fd_B_DOUBLE = md_B.Fields().ByName("DOUBLE") - fd_B_MAP = md_B.Fields().ByName("MAP") -} - -var _ protoreflect.Message = (*fastReflection_B)(nil) - -type fastReflection_B B - -func (x *B) ProtoReflect() protoreflect.Message { - return (*fastReflection_B)(x) -} - -func (x *B) slowProtoReflect() protoreflect.Message { - mi := &file__1_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -var _fastReflection_B_messageType fastReflection_B_messageType -var _ protoreflect.MessageType = fastReflection_B_messageType{} - -type fastReflection_B_messageType struct{} - -func (x fastReflection_B_messageType) Zero() protoreflect.Message { - return (*fastReflection_B)(nil) -} -func (x fastReflection_B_messageType) New() protoreflect.Message { - return new(fastReflection_B) -} -func (x fastReflection_B_messageType) Descriptor() protoreflect.MessageDescriptor { - return md_B -} - -// Descriptor returns message descriptor, which contains only the protobuf -// type information for the message. -func (x *fastReflection_B) Descriptor() protoreflect.MessageDescriptor { - return md_B -} - -// Type returns the message type, which encapsulates both Go and protobuf -// type information. If the Go type information is not needed, -// it is recommended that the message descriptor be used instead. -func (x *fastReflection_B) Type() protoreflect.MessageType { - return _fastReflection_B_messageType -} - -// New returns a newly allocated and mutable empty message. -func (x *fastReflection_B) New() protoreflect.Message { - return new(fastReflection_B) -} - -// Interface unwraps the message reflection interface and -// returns the underlying ProtoMessage interface. -func (x *fastReflection_B) Interface() protoreflect.ProtoMessage { - return (*B)(x) -} - -// Range iterates over every populated field in an undefined order, -// calling f for each field descriptor and value encountered. -// Range returns immediately if f returns false. -// While iterating, mutating operations may only be performed -// on the current field descriptor. -func (x *fastReflection_B) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.INT32 != int32(0) { - value := protoreflect.ValueOfInt32(x.INT32) - if !f(fd_B_INT32, value) { - return - } - } - if x.SINT32 != int32(0) { - value := protoreflect.ValueOfInt32(x.SINT32) - if !f(fd_B_SINT32, value) { - return - } - } - if x.INT64 != int64(0) { - value := protoreflect.ValueOfInt64(x.INT64) - if !f(fd_B_INT64, value) { - return - } - } - if x.SING64 != int64(0) { - value := protoreflect.ValueOfInt64(x.SING64) - if !f(fd_B_SING64, value) { - return - } - } - if x.SFIXED32 != int32(0) { - value := protoreflect.ValueOfInt32(x.SFIXED32) - if !f(fd_B_SFIXED32, value) { - return - } - } - if x.FIXED32 != uint32(0) { - value := protoreflect.ValueOfUint32(x.FIXED32) - if !f(fd_B_FIXED32, value) { - return - } - } - if x.FLOAT != float32(0) || math.Signbit(float64(x.FLOAT)) { - value := protoreflect.ValueOfFloat32(x.FLOAT) - if !f(fd_B_FLOAT, value) { - return - } - } - if x.SFIXED64 != int64(0) { - value := protoreflect.ValueOfInt64(x.SFIXED64) - if !f(fd_B_SFIXED64, value) { - return - } - } - if x.FIXED64 != uint64(0) { - value := protoreflect.ValueOfUint64(x.FIXED64) - if !f(fd_B_FIXED64, value) { - return - } - } - if x.DOUBLE != float64(0) || math.Signbit(x.DOUBLE) { - value := protoreflect.ValueOfFloat64(x.DOUBLE) - if !f(fd_B_DOUBLE, value) { - return - } - } - if len(x.MAP) != 0 { - value := protoreflect.ValueOfMap(&_B_11_map{m: &x.MAP}) - if !f(fd_B_MAP, value) { - return - } - } -} - -// Has reports whether a field is populated. -// -// Some fields have the property of nullability where it is possible to -// distinguish between the default value of a field and whether the field -// was explicitly populated with the default value. Singular message fields, -// member fields of a oneof, and proto2 scalar fields are nullable. Such -// fields are populated only if explicitly set. -// -// In other cases (aside from the nullable cases above), -// a proto3 scalar field is populated if it contains a non-zero value, and -// a repeated field is populated if it is non-empty. -func (x *fastReflection_B) Has(fd protoreflect.FieldDescriptor) bool { - switch fd.FullName() { - case "B.INT32": - return x.INT32 != int32(0) - case "B.SINT32": - return x.SINT32 != int32(0) - case "B.INT64": - return x.INT64 != int64(0) - case "B.SING64": - return x.SING64 != int64(0) - case "B.SFIXED32": - return x.SFIXED32 != int32(0) - case "B.FIXED32": - return x.FIXED32 != uint32(0) - case "B.FLOAT": - return x.FLOAT != float32(0) || math.Signbit(float64(x.FLOAT)) - case "B.SFIXED64": - return x.SFIXED64 != int64(0) - case "B.FIXED64": - return x.FIXED64 != uint64(0) - case "B.DOUBLE": - return x.DOUBLE != float64(0) || math.Signbit(x.DOUBLE) - case "B.MAP": - return len(x.MAP) != 0 - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: B")) - } - panic(fmt.Errorf("message B does not contain field %s", fd.FullName())) - } -} - -// Clear clears the field such that a subsequent Has call reports false. -// -// Clearing an extension field clears both the extension type and value -// associated with the given field number. -// -// Clear is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_B) Clear(fd protoreflect.FieldDescriptor) { - switch fd.FullName() { - case "B.INT32": - x.INT32 = int32(0) - case "B.SINT32": - x.SINT32 = int32(0) - case "B.INT64": - x.INT64 = int64(0) - case "B.SING64": - x.SING64 = int64(0) - case "B.SFIXED32": - x.SFIXED32 = int32(0) - case "B.FIXED32": - x.FIXED32 = uint32(0) - case "B.FLOAT": - x.FLOAT = float32(0) - case "B.SFIXED64": - x.SFIXED64 = int64(0) - case "B.FIXED64": - x.FIXED64 = uint64(0) - case "B.DOUBLE": - x.DOUBLE = float64(0) - case "B.MAP": - x.MAP = nil - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: B")) - } - panic(fmt.Errorf("message B does not contain field %s", fd.FullName())) - } -} - -// Get retrieves the value for a field. -// -// For unpopulated scalars, it returns the default value, where -// the default value of a bytes scalar is guaranteed to be a copy. -// For unpopulated composite types, it returns an empty, read-only view -// of the value; to obtain a mutable reference, use Mutable. -func (x *fastReflection_B) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - switch descriptor.FullName() { - case "B.INT32": - value := x.INT32 - return protoreflect.ValueOfInt32(value) - case "B.SINT32": - value := x.SINT32 - return protoreflect.ValueOfInt32(value) - case "B.INT64": - value := x.INT64 - return protoreflect.ValueOfInt64(value) - case "B.SING64": - value := x.SING64 - return protoreflect.ValueOfInt64(value) - case "B.SFIXED32": - value := x.SFIXED32 - return protoreflect.ValueOfInt32(value) - case "B.FIXED32": - value := x.FIXED32 - return protoreflect.ValueOfUint32(value) - case "B.FLOAT": - value := x.FLOAT - return protoreflect.ValueOfFloat32(value) - case "B.SFIXED64": - value := x.SFIXED64 - return protoreflect.ValueOfInt64(value) - case "B.FIXED64": - value := x.FIXED64 - return protoreflect.ValueOfUint64(value) - case "B.DOUBLE": - value := x.DOUBLE - return protoreflect.ValueOfFloat64(value) - case "B.MAP": - if len(x.MAP) == 0 { - return protoreflect.ValueOfMap(&_B_11_map{}) - } - mapValue := &_B_11_map{m: &x.MAP} - return protoreflect.ValueOfMap(mapValue) - default: - if descriptor.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: B")) - } - panic(fmt.Errorf("message B does not contain field %s", descriptor.FullName())) - } -} - -// Set stores the value for a field. -// -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType. -// When setting a composite type, it is unspecified whether the stored value -// aliases the source's memory in any way. If the composite value is an -// empty, read-only value, then it panics. -// -// Set is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_B) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { - switch fd.FullName() { - case "B.INT32": - x.INT32 = int32(value.Int()) - case "B.SINT32": - x.SINT32 = int32(value.Int()) - case "B.INT64": - x.INT64 = value.Int() - case "B.SING64": - x.SING64 = value.Int() - case "B.SFIXED32": - x.SFIXED32 = int32(value.Int()) - case "B.FIXED32": - x.FIXED32 = uint32(value.Uint()) - case "B.FLOAT": - x.FLOAT = float32(value.Float()) - case "B.SFIXED64": - x.SFIXED64 = value.Int() - case "B.FIXED64": - x.FIXED64 = value.Uint() - case "B.DOUBLE": - x.DOUBLE = value.Float() - case "B.MAP": - mv := value.Map() - cmv := mv.(*_B_11_map) - x.MAP = *cmv.m - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: B")) - } - panic(fmt.Errorf("message B does not contain field %s", fd.FullName())) - } -} - -// Mutable returns a mutable reference to a composite type. -// -// If the field is unpopulated, it may allocate a composite value. -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType -// if not already stored. -// It panics if the field does not contain a composite type. -// -// Mutable is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_B) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "B.MAP": - if x.MAP == nil { - x.MAP = make(map[string]*B) - } - value := &_B_11_map{m: &x.MAP} - return protoreflect.ValueOfMap(value) - case "B.INT32": - panic(fmt.Errorf("field INT32 of message B is not mutable")) - case "B.SINT32": - panic(fmt.Errorf("field SINT32 of message B is not mutable")) - case "B.INT64": - panic(fmt.Errorf("field INT64 of message B is not mutable")) - case "B.SING64": - panic(fmt.Errorf("field SING64 of message B is not mutable")) - case "B.SFIXED32": - panic(fmt.Errorf("field SFIXED32 of message B is not mutable")) - case "B.FIXED32": - panic(fmt.Errorf("field FIXED32 of message B is not mutable")) - case "B.FLOAT": - panic(fmt.Errorf("field FLOAT of message B is not mutable")) - case "B.SFIXED64": - panic(fmt.Errorf("field SFIXED64 of message B is not mutable")) - case "B.FIXED64": - panic(fmt.Errorf("field FIXED64 of message B is not mutable")) - case "B.DOUBLE": - panic(fmt.Errorf("field DOUBLE of message B is not mutable")) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: B")) - } - panic(fmt.Errorf("message B does not contain field %s", fd.FullName())) - } -} - -// NewField returns a new value that is assignable to the field -// for the given descriptor. For scalars, this returns the default value. -// For lists, maps, and messages, this returns a new, empty, mutable value. -func (x *fastReflection_B) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "B.INT32": - return protoreflect.ValueOfInt32(int32(0)) - case "B.SINT32": - return protoreflect.ValueOfInt32(int32(0)) - case "B.INT64": - return protoreflect.ValueOfInt64(int64(0)) - case "B.SING64": - return protoreflect.ValueOfInt64(int64(0)) - case "B.SFIXED32": - return protoreflect.ValueOfInt32(int32(0)) - case "B.FIXED32": - return protoreflect.ValueOfUint32(uint32(0)) - case "B.FLOAT": - return protoreflect.ValueOfFloat32(float32(0)) - case "B.SFIXED64": - return protoreflect.ValueOfInt64(int64(0)) - case "B.FIXED64": - return protoreflect.ValueOfUint64(uint64(0)) - case "B.DOUBLE": - return protoreflect.ValueOfFloat64(float64(0)) - case "B.MAP": - m := make(map[string]*B) - return protoreflect.ValueOfMap(&_B_11_map{m: &m}) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: B")) - } - panic(fmt.Errorf("message B does not contain field %s", fd.FullName())) - } -} - -// WhichOneof reports which field within the oneof is populated, -// returning nil if none are populated. -// It panics if the oneof descriptor does not belong to this message. -func (x *fastReflection_B) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { - switch d.FullName() { - default: - panic(fmt.Errorf("%s is not a oneof field in B", d.FullName())) - } - panic("unreachable") -} - -// GetUnknown retrieves the entire list of unknown fields. -// The caller may only mutate the contents of the RawFields -// if the mutated bytes are stored back into the message with SetUnknown. -func (x *fastReflection_B) GetUnknown() protoreflect.RawFields { - return x.unknownFields -} - -// SetUnknown stores an entire list of unknown fields. -// The raw fields must be syntactically valid according to the wire format. -// An implementation may panic if this is not the case. -// Once stored, the caller must not mutate the content of the RawFields. -// An empty RawFields may be passed to clear the fields. -// -// SetUnknown is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_B) SetUnknown(fields protoreflect.RawFields) { - x.unknownFields = fields -} - -// IsValid reports whether the message is valid. -// -// An invalid message is an empty, read-only value. -// -// An invalid message often corresponds to a nil pointer of the concrete -// message type, but the details are implementation dependent. -// Validity is not part of the protobuf data model, and may not -// be preserved in marshaling or other operations. -func (x *fastReflection_B) IsValid() bool { - return x != nil -} - -// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. -// This method may return nil. -// -// The returned methods type is identical to -// "google.golang.org/protobuf/runtime/protoiface".Methods. -// Consult the protoiface package documentation for details. -func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { - size := func(input protoiface.SizeInput) protoiface.SizeOutput { - x := input.Message.Interface().(*B) - if x == nil { - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: 0, - } - } - options := runtime.SizeInputToOptions(input) - _ = options - var n int - var l int - _ = l - if x.INT32 != 0 { - n += 1 + runtime.Sov(uint64(x.INT32)) - } - if x.SINT32 != 0 { - n += 1 + runtime.Soz(uint64(x.SINT32)) - } - if x.INT64 != 0 { - n += 1 + runtime.Sov(uint64(x.INT64)) - } - if x.SING64 != 0 { - n += 1 + runtime.Soz(uint64(x.SING64)) - } - if x.SFIXED32 != 0 { - n += 5 - } - if x.FIXED32 != 0 { - n += 5 - } - if x.FLOAT != 0 || math.Signbit(float64(x.FLOAT)) { - n += 5 - } - if x.SFIXED64 != 0 { - n += 9 - } - if x.FIXED64 != 0 { - n += 9 - } - if x.DOUBLE != 0 || math.Signbit(x.DOUBLE) { - n += 9 - } - if len(x.MAP) > 0 { - SiZeMaP := func(k string, v *B) { - l := 0 - if v != nil { - l = options.Size(v) - } - l += 1 + runtime.Sov(uint64(l)) - mapEntrySize := 1 + len(k) + runtime.Sov(uint64(len(k))) + l - n += mapEntrySize + 1 + runtime.Sov(uint64(mapEntrySize)) - } - if options.Deterministic { - sortme := make([]string, 0, len(x.MAP)) - for k := range x.MAP { - sortme = append(sortme, k) - } - sort.Strings(sortme) - for _, k := range sortme { - v := x.MAP[k] - SiZeMaP(k, v) - } - } else { - for k, v := range x.MAP { - SiZeMaP(k, v) - } - } - } - if x.unknownFields != nil { - n += len(x.unknownFields) - } - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: n, - } - } - - marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { - x := input.Message.Interface().(*B) - if x == nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - options := runtime.MarshalInputToOptions(input) - _ = options - size := options.Size(x) - dAtA := make([]byte, size) - i := len(dAtA) - _ = i - var l int - _ = l - if x.unknownFields != nil { - i -= len(x.unknownFields) - copy(dAtA[i:], x.unknownFields) - } - if len(x.MAP) > 0 { - MaRsHaLmAp := func(k string, v *B) (protoiface.MarshalOutput, error) { - baseI := i - encoded, err := options.Marshal(v) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x12 - i -= len(k) - copy(dAtA[i:], k) - i = runtime.EncodeVarint(dAtA, i, uint64(len(k))) - i-- - dAtA[i] = 0xa - i = runtime.EncodeVarint(dAtA, i, uint64(baseI-i)) - i-- - dAtA[i] = 0x5a - return protoiface.MarshalOutput{}, nil - } - if options.Deterministic { - keysForMAP := make([]string, 0, len(x.MAP)) - for k := range x.MAP { - keysForMAP = append(keysForMAP, string(k)) - } - sort.Slice(keysForMAP, func(i, j int) bool { - return keysForMAP[i] < keysForMAP[j] - }) - for iNdEx := len(keysForMAP) - 1; iNdEx >= 0; iNdEx-- { - v := x.MAP[string(keysForMAP[iNdEx])] - out, err := MaRsHaLmAp(keysForMAP[iNdEx], v) - if err != nil { - return out, err + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break } } - } else { - for k := range x.MAP { - v := x.MAP[k] - out, err := MaRsHaLmAp(k, v) - if err != nil { - return out, err + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.COIN == nil { + x.COIN = &v1beta1.Coin{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.COIN); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field COINS", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break } } - } - } - if x.DOUBLE != 0 || math.Signbit(x.DOUBLE) { - i -= 8 - binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(x.DOUBLE)))) - i-- - dAtA[i] = 0x51 - } - if x.FIXED64 != 0 { - i -= 8 - binary.LittleEndian.PutUint64(dAtA[i:], uint64(x.FIXED64)) - i-- - dAtA[i] = 0x49 - } - if x.SFIXED64 != 0 { - i -= 8 - binary.LittleEndian.PutUint64(dAtA[i:], uint64(x.SFIXED64)) - i-- - dAtA[i] = 0x41 - } - if x.FLOAT != 0 || math.Signbit(float64(x.FLOAT)) { - i -= 4 - binary.LittleEndian.PutUint32(dAtA[i:], uint32(math.Float32bits(float32(x.FLOAT)))) - i-- - dAtA[i] = 0x3d - } - if x.FIXED32 != 0 { - i -= 4 - binary.LittleEndian.PutUint32(dAtA[i:], uint32(x.FIXED32)) - i-- - dAtA[i] = 0x35 - } - if x.SFIXED32 != 0 { - i -= 4 - binary.LittleEndian.PutUint32(dAtA[i:], uint32(x.SFIXED32)) - i-- - dAtA[i] = 0x2d - } - if x.SING64 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64((uint64(x.SING64)<<1)^uint64((x.SING64>>63)))) - i-- - dAtA[i] = 0x20 - } - if x.INT64 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.INT64)) - i-- - dAtA[i] = 0x18 - } - if x.SINT32 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64((uint32(x.SINT32)<<1)^uint32((x.SINT32>>31)))) - i-- - dAtA[i] = 0x10 - } - if x.INT32 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.INT32)) - i-- - dAtA[i] = 0x8 - } - if input.Buf != nil { - input.Buf = append(input.Buf, dAtA...) - } else { - input.Buf = dAtA - } - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { - x := input.Message.Interface().(*B) - if x == nil { - return protoiface.UnmarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Flags: input.Flags, - }, nil - } - options := runtime.UnmarshalInputToOptions(input) - _ = options - dAtA := input.Buf - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength } - if iNdEx >= l { + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break + x.COINS = append(x.COINS, &v1beta1.Coin{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.COINS[len(x.COINS)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: B: wiretype end group for non-group") - } - if fieldNum <= 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: B: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field INT32", wireType) + iNdEx = postIndex + case 9: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field BYTES", wireType) } - x.INT32 = 0 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow @@ -1885,16 +1419,31 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { } b := dAtA[iNdEx] iNdEx++ - x.INT32 |= int32(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - case 2: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SINT32", wireType) + if byteLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength } - var v int32 + postIndex := iNdEx + byteLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.BYTES = append(x.BYTES[:0], dAtA[iNdEx:postIndex]...) + if x.BYTES == nil { + x.BYTES = []byte{} + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field TIMESTAMP", wireType) + } + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow @@ -1904,18 +1453,33 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { } b := dAtA[iNdEx] iNdEx++ - v |= int32(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31)) - x.SINT32 = v - case 3: + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.TIMESTAMP == nil { + x.TIMESTAMP = ×tamppb.Timestamp{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.TIMESTAMP); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 101: if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field INT64", wireType) + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SINT32", wireType) } - x.INT64 = 0 + var v int32 for shift := uint(0); ; shift += 7 { if shift >= 64 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow @@ -1925,14 +1489,16 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { } b := dAtA[iNdEx] iNdEx++ - x.INT64 |= int64(b&0x7F) << shift + v |= int32(b&0x7F) << shift if b < 0x80 { break } } - case 4: + v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31)) + x.SINT32 = v + case 102: if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SING64", wireType) + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SINT64", wireType) } var v uint64 for shift := uint(0); ; shift += 7 { @@ -1950,8 +1516,8 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { } } v = (v >> 1) ^ uint64((int64(v&1)<<63)>>63) - x.SING64 = int64(v) - case 5: + x.SINT64 = int64(v) + case 105: if wireType != 5 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SFIXED32", wireType) } @@ -1961,7 +1527,7 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { } x.SFIXED32 = int32(binary.LittleEndian.Uint32(dAtA[iNdEx:])) iNdEx += 4 - case 6: + case 106: if wireType != 5 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field FIXED32", wireType) } @@ -1971,7 +1537,7 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { } x.FIXED32 = uint32(binary.LittleEndian.Uint32(dAtA[iNdEx:])) iNdEx += 4 - case 7: + case 107: if wireType != 5 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field FLOAT", wireType) } @@ -1982,7 +1548,7 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { v = uint32(binary.LittleEndian.Uint32(dAtA[iNdEx:])) iNdEx += 4 x.FLOAT = float32(math.Float32frombits(v)) - case 8: + case 108: if wireType != 1 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SFIXED64", wireType) } @@ -1992,7 +1558,7 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { } x.SFIXED64 = int64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) iNdEx += 8 - case 9: + case 109: if wireType != 1 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field FIXED64", wireType) } @@ -2002,7 +1568,7 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { } x.FIXED64 = uint64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) iNdEx += 8 - case 10: + case 110: if wireType != 1 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DOUBLE", wireType) } @@ -2013,7 +1579,7 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { v = uint64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) iNdEx += 8 x.DOUBLE = float64(math.Float64frombits(v)) - case 11: + case 111: if wireType != 2 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field MAP", wireType) } @@ -2043,10 +1609,10 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF } if x.MAP == nil { - x.MAP = make(map[string]*B) + x.MAP = make(map[string]*A) } var mapkey string - var mapvalue *B + var mapvalue *A for iNdEx < postIndex { entryPreIndex := iNdEx var wire uint64 @@ -2120,7 +1686,7 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { if postmsgIndex > l { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF } - mapvalue = &B{} + mapvalue = &A{} if err := options.Unmarshal(dAtA[iNdEx:postmsgIndex], mapvalue); err != nil { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err } @@ -2236,12 +1802,13 @@ func (Enumeration) EnumDescriptor() ([]byte, []int) { return file__1_proto_rawDescGZIP(), []int{0} } -// A contains fields that are parseable by SIGN_MODE_TEXTUAL. +// A is used for testing value renderers. type A struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + // Fields that are parseable by SIGN_MODE_TEXTUAL. UINT32 uint32 `protobuf:"varint,1,opt,name=UINT32,proto3" json:"UINT32,omitempty"` UINT64 uint64 `protobuf:"varint,2,opt,name=UINT64,proto3" json:"UINT64,omitempty"` INT32 int32 `protobuf:"varint,3,opt,name=INT32,proto3" json:"INT32,omitempty"` @@ -2252,6 +1819,16 @@ type A struct { COINS []*v1beta1.Coin `protobuf:"bytes,8,rep,name=COINS,proto3" json:"COINS,omitempty"` BYTES []byte `protobuf:"bytes,9,opt,name=BYTES,proto3" json:"BYTES,omitempty"` TIMESTAMP *timestamppb.Timestamp `protobuf:"bytes,10,opt,name=TIMESTAMP,proto3" json:"TIMESTAMP,omitempty"` + // Fields that are not handled by SIGN_MODE_TEXTUAL. + SINT32 int32 `protobuf:"zigzag32,101,opt,name=SINT32,proto3" json:"SINT32,omitempty"` + SINT64 int64 `protobuf:"zigzag64,102,opt,name=SINT64,proto3" json:"SINT64,omitempty"` + SFIXED32 int32 `protobuf:"fixed32,105,opt,name=SFIXED32,proto3" json:"SFIXED32,omitempty"` + FIXED32 uint32 `protobuf:"fixed32,106,opt,name=FIXED32,proto3" json:"FIXED32,omitempty"` + FLOAT float32 `protobuf:"fixed32,107,opt,name=FLOAT,proto3" json:"FLOAT,omitempty"` + SFIXED64 int64 `protobuf:"fixed64,108,opt,name=SFIXED64,proto3" json:"SFIXED64,omitempty"` + FIXED64 uint64 `protobuf:"fixed64,109,opt,name=FIXED64,proto3" json:"FIXED64,omitempty"` + DOUBLE float64 `protobuf:"fixed64,110,opt,name=DOUBLE,proto3" json:"DOUBLE,omitempty"` + MAP map[string]*A `protobuf:"bytes,111,rep,name=MAP,proto3" json:"MAP,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (x *A) Reset() { @@ -2344,117 +1921,63 @@ func (x *A) GetTIMESTAMP() *timestamppb.Timestamp { return nil } -// B contains fields that are not parseable by SIGN_MODE_TEXTUAL, some fields -// may be moved to A at some point. -type B struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - INT32 int32 `protobuf:"varint,1,opt,name=INT32,proto3" json:"INT32,omitempty"` - SINT32 int32 `protobuf:"zigzag32,2,opt,name=SINT32,proto3" json:"SINT32,omitempty"` - INT64 int64 `protobuf:"varint,3,opt,name=INT64,proto3" json:"INT64,omitempty"` - SING64 int64 `protobuf:"zigzag64,4,opt,name=SING64,proto3" json:"SING64,omitempty"` - SFIXED32 int32 `protobuf:"fixed32,5,opt,name=SFIXED32,proto3" json:"SFIXED32,omitempty"` - FIXED32 uint32 `protobuf:"fixed32,6,opt,name=FIXED32,proto3" json:"FIXED32,omitempty"` - FLOAT float32 `protobuf:"fixed32,7,opt,name=FLOAT,proto3" json:"FLOAT,omitempty"` - SFIXED64 int64 `protobuf:"fixed64,8,opt,name=SFIXED64,proto3" json:"SFIXED64,omitempty"` - FIXED64 uint64 `protobuf:"fixed64,9,opt,name=FIXED64,proto3" json:"FIXED64,omitempty"` - DOUBLE float64 `protobuf:"fixed64,10,opt,name=DOUBLE,proto3" json:"DOUBLE,omitempty"` - MAP map[string]*B `protobuf:"bytes,11,rep,name=MAP,proto3" json:"MAP,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` -} - -func (x *B) Reset() { - *x = B{} - if protoimpl.UnsafeEnabled { - mi := &file__1_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *B) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*B) ProtoMessage() {} - -// Deprecated: Use B.ProtoReflect.Descriptor instead. -func (*B) Descriptor() ([]byte, []int) { - return file__1_proto_rawDescGZIP(), []int{1} -} - -func (x *B) GetINT32() int32 { - if x != nil { - return x.INT32 - } - return 0 -} - -func (x *B) GetSINT32() int32 { +func (x *A) GetSINT32() int32 { if x != nil { return x.SINT32 } return 0 } -func (x *B) GetINT64() int64 { +func (x *A) GetSINT64() int64 { if x != nil { - return x.INT64 - } - return 0 -} - -func (x *B) GetSING64() int64 { - if x != nil { - return x.SING64 + return x.SINT64 } return 0 } -func (x *B) GetSFIXED32() int32 { +func (x *A) GetSFIXED32() int32 { if x != nil { return x.SFIXED32 } return 0 } -func (x *B) GetFIXED32() uint32 { +func (x *A) GetFIXED32() uint32 { if x != nil { return x.FIXED32 } return 0 } -func (x *B) GetFLOAT() float32 { +func (x *A) GetFLOAT() float32 { if x != nil { return x.FLOAT } return 0 } -func (x *B) GetSFIXED64() int64 { +func (x *A) GetSFIXED64() int64 { if x != nil { return x.SFIXED64 } return 0 } -func (x *B) GetFIXED64() uint64 { +func (x *A) GetFIXED64() uint64 { if x != nil { return x.FIXED64 } return 0 } -func (x *B) GetDOUBLE() float64 { +func (x *A) GetDOUBLE() float64 { if x != nil { return x.DOUBLE } return 0 } -func (x *B) GetMAP() map[string]*B { +func (x *A) GetMAP() map[string]*A { if x != nil { return x.MAP } @@ -2472,7 +1995,7 @@ var file__1_proto_rawDesc = []byte{ 0x73, 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x69, - 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xdf, 0x02, 0x0a, 0x01, 0x41, 0x12, 0x16, 0x0a, + 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x84, 0x05, 0x0a, 0x01, 0x41, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x55, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x49, 0x4e, 0x54, 0x36, 0x34, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x55, 0x49, 0x4e, 0x54, 0x36, 0x34, 0x12, 0x14, 0x0a, @@ -2494,34 +2017,31 @@ var file__1_proto_rawDesc = []byte{ 0x38, 0x0a, 0x09, 0x54, 0x49, 0x4d, 0x45, 0x53, 0x54, 0x41, 0x4d, 0x50, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, - 0x54, 0x49, 0x4d, 0x45, 0x53, 0x54, 0x41, 0x4d, 0x50, 0x22, 0xd4, 0x02, 0x0a, 0x01, 0x42, 0x12, - 0x14, 0x0a, 0x05, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, - 0x49, 0x4e, 0x54, 0x33, 0x32, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x11, 0x52, 0x06, 0x53, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x12, 0x14, 0x0a, - 0x05, 0x49, 0x4e, 0x54, 0x36, 0x34, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x49, 0x4e, - 0x54, 0x36, 0x34, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x49, 0x4e, 0x47, 0x36, 0x34, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x12, 0x52, 0x06, 0x53, 0x49, 0x4e, 0x47, 0x36, 0x34, 0x12, 0x1a, 0x0a, 0x08, 0x53, - 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0f, 0x52, 0x08, 0x53, - 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, 0x12, 0x18, 0x0a, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, - 0x33, 0x32, 0x18, 0x06, 0x20, 0x01, 0x28, 0x07, 0x52, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, - 0x32, 0x12, 0x14, 0x0a, 0x05, 0x46, 0x4c, 0x4f, 0x41, 0x54, 0x18, 0x07, 0x20, 0x01, 0x28, 0x02, - 0x52, 0x05, 0x46, 0x4c, 0x4f, 0x41, 0x54, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x46, 0x49, 0x58, 0x45, - 0x44, 0x36, 0x34, 0x18, 0x08, 0x20, 0x01, 0x28, 0x10, 0x52, 0x08, 0x53, 0x46, 0x49, 0x58, 0x45, - 0x44, 0x36, 0x34, 0x12, 0x18, 0x0a, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, 0x34, 0x18, 0x09, - 0x20, 0x01, 0x28, 0x06, 0x52, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, 0x34, 0x12, 0x16, 0x0a, - 0x06, 0x44, 0x4f, 0x55, 0x42, 0x4c, 0x45, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x01, 0x52, 0x06, 0x44, - 0x4f, 0x55, 0x42, 0x4c, 0x45, 0x12, 0x1d, 0x0a, 0x03, 0x4d, 0x41, 0x50, 0x18, 0x0b, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x42, 0x2e, 0x4d, 0x41, 0x50, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, - 0x03, 0x4d, 0x41, 0x50, 0x1a, 0x3a, 0x0a, 0x08, 0x4d, 0x41, 0x50, 0x45, 0x6e, 0x74, 0x72, 0x79, - 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, - 0x65, 0x79, 0x12, 0x18, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x02, 0x2e, 0x42, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, - 0x2a, 0x1f, 0x0a, 0x0b, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, - 0x07, 0x0a, 0x03, 0x4f, 0x6e, 0x65, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x77, 0x6f, 0x10, - 0x01, 0x42, 0x33, 0x42, 0x06, 0x31, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x27, 0x63, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x74, 0x78, 0x2f, 0x74, - 0x65, 0x78, 0x74, 0x75, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, - 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x54, 0x49, 0x4d, 0x45, 0x53, 0x54, 0x41, 0x4d, 0x50, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x49, 0x4e, + 0x54, 0x33, 0x32, 0x18, 0x65, 0x20, 0x01, 0x28, 0x11, 0x52, 0x06, 0x53, 0x49, 0x4e, 0x54, 0x33, + 0x32, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x49, 0x4e, 0x54, 0x36, 0x34, 0x18, 0x66, 0x20, 0x01, 0x28, + 0x12, 0x52, 0x06, 0x53, 0x49, 0x4e, 0x54, 0x36, 0x34, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x46, 0x49, + 0x58, 0x45, 0x44, 0x33, 0x32, 0x18, 0x69, 0x20, 0x01, 0x28, 0x0f, 0x52, 0x08, 0x53, 0x46, 0x49, + 0x58, 0x45, 0x44, 0x33, 0x32, 0x12, 0x18, 0x0a, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, + 0x18, 0x6a, 0x20, 0x01, 0x28, 0x07, 0x52, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, 0x12, + 0x14, 0x0a, 0x05, 0x46, 0x4c, 0x4f, 0x41, 0x54, 0x18, 0x6b, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, + 0x46, 0x4c, 0x4f, 0x41, 0x54, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, + 0x34, 0x18, 0x6c, 0x20, 0x01, 0x28, 0x10, 0x52, 0x08, 0x53, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, + 0x34, 0x12, 0x18, 0x0a, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, 0x34, 0x18, 0x6d, 0x20, 0x01, + 0x28, 0x06, 0x52, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, 0x34, 0x12, 0x16, 0x0a, 0x06, 0x44, + 0x4f, 0x55, 0x42, 0x4c, 0x45, 0x18, 0x6e, 0x20, 0x01, 0x28, 0x01, 0x52, 0x06, 0x44, 0x4f, 0x55, + 0x42, 0x4c, 0x45, 0x12, 0x1d, 0x0a, 0x03, 0x4d, 0x41, 0x50, 0x18, 0x6f, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x0b, 0x2e, 0x41, 0x2e, 0x4d, 0x41, 0x50, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x03, 0x4d, + 0x41, 0x50, 0x1a, 0x3a, 0x0a, 0x08, 0x4d, 0x41, 0x50, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, + 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, + 0x12, 0x18, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x02, 0x2e, 0x41, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x2a, 0x1f, + 0x0a, 0x0b, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x07, 0x0a, + 0x03, 0x4f, 0x6e, 0x65, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x77, 0x6f, 0x10, 0x01, 0x42, + 0x33, 0x42, 0x06, 0x31, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x27, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x74, 0x78, 0x2f, 0x74, 0x65, 0x78, + 0x74, 0x75, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, + 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -2537,21 +2057,20 @@ func file__1_proto_rawDescGZIP() []byte { } var file__1_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file__1_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file__1_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file__1_proto_goTypes = []interface{}{ (Enumeration)(0), // 0: Enumeration (*A)(nil), // 1: A - (*B)(nil), // 2: B - nil, // 3: B.MAPEntry - (*v1beta1.Coin)(nil), // 4: cosmos.base.v1beta1.Coin - (*timestamppb.Timestamp)(nil), // 5: google.protobuf.Timestamp + nil, // 2: A.MAPEntry + (*v1beta1.Coin)(nil), // 3: cosmos.base.v1beta1.Coin + (*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp } var file__1_proto_depIdxs = []int32{ - 4, // 0: A.COIN:type_name -> cosmos.base.v1beta1.Coin - 4, // 1: A.COINS:type_name -> cosmos.base.v1beta1.Coin - 5, // 2: A.TIMESTAMP:type_name -> google.protobuf.Timestamp - 3, // 3: B.MAP:type_name -> B.MAPEntry - 2, // 4: B.MAPEntry.value:type_name -> B + 3, // 0: A.COIN:type_name -> cosmos.base.v1beta1.Coin + 3, // 1: A.COINS:type_name -> cosmos.base.v1beta1.Coin + 4, // 2: A.TIMESTAMP:type_name -> google.protobuf.Timestamp + 2, // 3: A.MAP:type_name -> A.MAPEntry + 1, // 4: A.MAPEntry.value:type_name -> A 5, // [5:5] is the sub-list for method output_type 5, // [5:5] is the sub-list for method input_type 5, // [5:5] is the sub-list for extension type_name @@ -2577,18 +2096,6 @@ func file__1_proto_init() { return nil } } - file__1_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*B); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } } type x struct{} out := protoimpl.TypeBuilder{ @@ -2596,7 +2103,7 @@ func file__1_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file__1_proto_rawDesc, NumEnums: 1, - NumMessages: 3, + NumMessages: 2, NumExtensions: 0, NumServices: 0, }, diff --git a/tx/textual/valuerenderer/bytes.go b/tx/textual/valuerenderer/bytes.go index f2206a00cf84..7e7eba8da958 100644 --- a/tx/textual/valuerenderer/bytes.go +++ b/tx/textual/valuerenderer/bytes.go @@ -9,7 +9,12 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" ) -// bytesValueRenderer implements ValueRenderer for bytes +// NewBytesValueRenderer returns a ValueRenderer for Protobuf bytes, which are +// encoded as capital-letter hexadecimal, without the '0x' prefix. +func NewBytesValueRenderer() ValueRenderer { + return bytesValueRenderer{} +} + type bytesValueRenderer struct{} var _ ValueRenderer = bytesValueRenderer{} diff --git a/tx/textual/valuerenderer/bytes_test.go b/tx/textual/valuerenderer/bytes_test.go index 457f5ec93406..87b1c7246529 100644 --- a/tx/textual/valuerenderer/bytes_test.go +++ b/tx/textual/valuerenderer/bytes_test.go @@ -8,6 +8,7 @@ import ( "strings" "testing" + "cosmossdk.io/tx/textual/valuerenderer" "github.com/stretchr/testify/require" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -18,15 +19,16 @@ func TestBytesJsonTestCases(t *testing.T) { // their expected results in hex. raw, err := os.ReadFile("../internal/testdata/bytes.json") require.NoError(t, err) - err = json.Unmarshal(raw, &testcases) require.NoError(t, err) + textual := valuerenderer.NewTextual(mockCoinMetadataQuerier) + for _, tc := range testcases { data, err := base64.StdEncoding.DecodeString(tc.base64) require.NoError(t, err) - valrend, err := valueRendererOf(data) + valrend, err := textual.GetValueRenderer(fieldDescriptorFromName("BYTES")) require.NoError(t, err) b := new(strings.Builder) diff --git a/tx/textual/valuerenderer/coin_test.go b/tx/textual/valuerenderer/coin_test.go new file mode 100644 index 000000000000..f48509b38d32 --- /dev/null +++ b/tx/textual/valuerenderer/coin_test.go @@ -0,0 +1,101 @@ +package valuerenderer_test + +import ( + "context" + "encoding/json" + "fmt" + "os" + "strings" + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/reflect/protoreflect" + + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + "cosmossdk.io/tx/textual/valuerenderer" +) + +// mockCoinMetadataKey is used in the mock coin metadata querier. +func mockCoinMetadataKey(denom string) string { + return fmt.Sprintf("%s-%s", "coin-metadata", denom) +} + +// mockCoinMetadataQuerier is a mock querier for coin metadata used for test +// purposes. +func mockCoinMetadataQuerier(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { + v := ctx.Value(mockCoinMetadataKey(denom)) + if v == nil { + return nil, nil + } + + return v.(*bankv1beta1.Metadata), nil +} + +func TestMetadataQuerier(t *testing.T) { + b := new(strings.Builder) + + // Errors on nil metadata querier + textual := valuerenderer.NewTextual(nil) + vr, err := textual.GetValueRenderer(fieldDescriptorFromName("COIN")) + require.NoError(t, err) + err = vr.Format(context.Background(), protoreflect.ValueOf((&basev1beta1.Coin{}).ProtoReflect()), b) + require.Error(t, err) + + // Errors if metadata querier returns an error + expErr := fmt.Errorf("mock error") + textual = valuerenderer.NewTextual(func(_ context.Context, _ string) (*bankv1beta1.Metadata, error) { + return nil, expErr + }) + vr, err = textual.GetValueRenderer(fieldDescriptorFromName("COIN")) + require.NoError(t, err) + err = vr.Format(context.Background(), protoreflect.ValueOf((&basev1beta1.Coin{}).ProtoReflect()), b) + require.ErrorIs(t, err, expErr) + err = vr.Format(context.Background(), protoreflect.ValueOf(NewGenericList([]*basev1beta1.Coin{{}})), b) + require.ErrorIs(t, err, expErr) +} + +func TestCoinJsonTestcases(t *testing.T) { + var testcases []coinJsonTest + raw, err := os.ReadFile("../internal/testdata/coin.json") + require.NoError(t, err) + err = json.Unmarshal(raw, &testcases) + require.NoError(t, err) + + textual := valuerenderer.NewTextual(mockCoinMetadataQuerier) + vr, err := textual.GetValueRenderer(fieldDescriptorFromName("COIN")) + require.NoError(t, err) + + for _, tc := range testcases { + t.Run(tc.Text, func(t *testing.T) { + if tc.Proto != nil { + ctx := context.WithValue(context.Background(), mockCoinMetadataKey(tc.Proto.Denom), tc.Metadata) + b := new(strings.Builder) + err = vr.Format(ctx, protoreflect.ValueOf(tc.Proto.ProtoReflect()), b) + + if tc.Error { + require.Error(t, err) + return + } + + require.NoError(t, err) + require.Equal(t, tc.Text, b.String()) + } + + // TODO Add parsing tests + // https://github.com/cosmos/cosmos-sdk/issues/13153 + }) + } +} + +// coinJsonTest is the type of test cases in the testdata file. +// If the test case has a Proto, try to Format() it. If Error is set, expect +// an error, otherwise match Text, then Parse() the text and expect it to +// match (via proto.Equals()) the original Proto. If the test case has no +// Proto, try to Parse() the Text and expect an error if Error is set. +type coinJsonTest struct { + Proto *basev1beta1.Coin + Metadata *bankv1beta1.Metadata + Error bool + Text string +} diff --git a/tx/textual/valuerenderer/coins.go b/tx/textual/valuerenderer/coins.go new file mode 100644 index 000000000000..0b3b302dd938 --- /dev/null +++ b/tx/textual/valuerenderer/coins.go @@ -0,0 +1,168 @@ +package valuerenderer + +import ( + "context" + "fmt" + "io" + "sort" + "strings" + + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + "cosmossdk.io/math" + "google.golang.org/protobuf/reflect/protoreflect" +) + +// NewCoinsValueRenderer returns a ValueRenderer for SDK Coin and Coins. +func NewCoinsValueRenderer(q CoinMetadataQueryFn) ValueRenderer { + return coinsValueRenderer{q} +} + +type coinsValueRenderer struct { + // coinMetadataQuerier defines a function to query the coin metadata from + // state. It should use bank module's `DenomsMetadata` gRPC query to fetch + // each denom's associated metadata, either using the bank keeper (for + // server-side code) or a gRPC query client (for client-side code). + coinMetadataQuerier CoinMetadataQueryFn +} + +var _ ValueRenderer = coinsValueRenderer{} + +func (vr coinsValueRenderer) Format(ctx context.Context, v protoreflect.Value, w io.Writer) error { + if vr.coinMetadataQuerier == nil { + return fmt.Errorf("expected non-nil coin metadata querier") + } + + // Check whether we have a Coin or some Coins. + switch protoCoins := v.Interface().(type) { + // If it's a repeated Coin: + case protoreflect.List: + { + coins, metadatas := make([]*basev1beta1.Coin, protoCoins.Len()), make([]*bankv1beta1.Metadata, protoCoins.Len()) + var err error + for i := 0; i < protoCoins.Len(); i++ { + coin := protoCoins.Get(i).Interface().(protoreflect.Message).Interface().(*basev1beta1.Coin) + coins[i] = coin + metadatas[i], err = vr.coinMetadataQuerier(ctx, coin.Denom) + if err != nil { + return err + } + } + + formatted, err := formatCoins(coins, metadatas) + if err != nil { + return err + } + + _, err = w.Write([]byte(formatted)) + return err + } + // If it's a single Coin: + case protoreflect.Message: + { + coin := v.Interface().(protoreflect.Message).Interface().(*basev1beta1.Coin) + + metadata, err := vr.coinMetadataQuerier(ctx, coin.Denom) + if err != nil { + return err + } + + formatted, err := formatCoin(coin, metadata) + if err != nil { + return err + } + + _, err = w.Write([]byte(formatted)) + return err + } + default: + return fmt.Errorf("got invalid type %t for coins", v.Interface()) + } + +} + +func (vr coinsValueRenderer) Parse(_ context.Context, r io.Reader) (protoreflect.Value, error) { + // ref: https://github.com/cosmos/cosmos-sdk/issues/13153 + panic("implement me, see #13153") +} + +// formatCoin formats a sdk.Coin into a value-rendered string, using the +// given metadata about the denom. It returns the formatted coin string, the +// display denom, and an optional error. +func formatCoin(coin *basev1beta1.Coin, metadata *bankv1beta1.Metadata) (string, error) { + coinDenom := coin.Denom + + // Return early if no display denom or display denom is the current coin denom. + if metadata == nil || metadata.Display == "" || coinDenom == metadata.Display { + vr, err := formatDecimal(coin.Amount) + return vr + " " + coin.Denom, err + } + + dispDenom := metadata.Display + + // Find exponents of both denoms. + var coinExp, dispExp uint32 + foundCoinExp, foundDispExp := false, false + for _, unit := range metadata.DenomUnits { + if coinDenom == unit.Denom { + coinExp = unit.Exponent + foundCoinExp = true + } + if dispDenom == unit.Denom { + dispExp = unit.Exponent + foundDispExp = true + } + } + + // If we didn't find either exponent, then we return early. + if !foundCoinExp || !foundDispExp { + vr, err := formatInteger(coin.Amount) + return vr + " " + coin.Denom, err + } + + exponentDiff := int64(coinExp) - int64(dispExp) + + dispAmount, err := math.LegacyNewDecFromStr(coin.Amount) + if err != nil { + return "", err + } + + if exponentDiff > 0 { + dispAmount = dispAmount.Mul(math.LegacyNewDec(10).Power(uint64(exponentDiff))) + } else { + dispAmount = dispAmount.Quo(math.LegacyNewDec(10).Power(uint64(-exponentDiff))) + } + + vr, err := formatDecimal(dispAmount.String()) + return vr + " " + dispDenom, err +} + +// formatCoins formats Coins into a value-rendered string, which uses +// `formatCoin` separated by ", " (a comma and a space), and sorted +// alphabetically by value-rendered denoms. It expects an array of metadata +// (optionally nil), where each metadata at index `i` MUST match the coin denom +// at the same index. +func formatCoins(coins []*basev1beta1.Coin, metadata []*bankv1beta1.Metadata) (string, error) { + if len(coins) != len(metadata) { + panic(fmt.Errorf("formatCoins expect one metadata for each coin; expected %d, got %d", len(coins), len(metadata))) + } + + formatted := make([]string, len(coins)) + for i, coin := range coins { + var err error + formatted[i], err = formatCoin(coin, metadata[i]) + if err != nil { + return "", err + } + } + + // Sort the formatted coins by display denom. + sort.SliceStable(formatted, func(i, j int) bool { + denomI := strings.Split(formatted[i], " ")[1] + denomJ := strings.Split(formatted[j], " ")[1] + + return denomI < denomJ + }) + + return strings.Join(formatted, ", "), nil +} diff --git a/tx/textual/valuerenderer/coins_test.go b/tx/textual/valuerenderer/coins_test.go new file mode 100644 index 000000000000..b8f2abcc8bb5 --- /dev/null +++ b/tx/textual/valuerenderer/coins_test.go @@ -0,0 +1,67 @@ +package valuerenderer_test + +import ( + "context" + "encoding/json" + "os" + "strings" + "testing" + + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + "cosmossdk.io/tx/textual/valuerenderer" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/reflect/protoreflect" +) + +func TestCoinsJsonTestcases(t *testing.T) { + var testcases []coinsJsonTest + raw, err := os.ReadFile("../internal/testdata/coins.json") + require.NoError(t, err) + err = json.Unmarshal(raw, &testcases) + require.NoError(t, err) + + textual := valuerenderer.NewTextual(mockCoinMetadataQuerier) + vr, err := textual.GetValueRenderer(fieldDescriptorFromName("COINS")) + require.NoError(t, err) + + for _, tc := range testcases { + t.Run(tc.Text, func(t *testing.T) { + if tc.Proto != nil { + // Create a context.Context containing all coins metadata, to simulate + // that they are in state. + ctx := context.Background() + for _, coin := range tc.Proto { + ctx = context.WithValue(ctx, mockCoinMetadataKey(coin.Denom), tc.Metadata[coin.Denom]) + } + + b := new(strings.Builder) + listValue := NewGenericList(tc.Proto) + err = vr.Format(ctx, protoreflect.ValueOf(listValue), b) + + if tc.Error { + require.Error(t, err) + return + } + + require.NoError(t, err) + require.Equal(t, tc.Text, b.String()) + } + + // TODO Add parsing tests + // https://github.com/cosmos/cosmos-sdk/issues/13153 + }) + } +} + +// coinsJsonTest is the type of test cases in the testdata file. +// If the test case has a Proto, try to Format() it. If Error is set, expect +// an error, otherwise match Text, then Parse() the text and expect it to +// match (via proto.Equals()) the original Proto. If the test case has no +// Proto, try to Parse() the Text and expect an error if Error is set. +type coinsJsonTest struct { + Proto []*basev1beta1.Coin + Metadata map[string]*bankv1beta1.Metadata + Text string + Error bool +} diff --git a/tx/textual/valuerenderer/dec.go b/tx/textual/valuerenderer/dec.go index 6c26876613b0..a3ab675220ea 100644 --- a/tx/textual/valuerenderer/dec.go +++ b/tx/textual/valuerenderer/dec.go @@ -11,6 +11,12 @@ import ( const thousandSeparator string = "'" +// NewDecValueRenderer returns a ValueRenderer for encoding sdk.Dec cosmos +// scalars. +func NewDecValueRenderer() ValueRenderer { + return decValueRenderer{} +} + type decValueRenderer struct{} var _ ValueRenderer = decValueRenderer{} diff --git a/tx/textual/valuerenderer/int.go b/tx/textual/valuerenderer/int.go index 572f3b9b170a..6197c405e539 100644 --- a/tx/textual/valuerenderer/int.go +++ b/tx/textual/valuerenderer/int.go @@ -9,6 +9,12 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" ) +// NewIntValueRenderer returns a ValueRenderer for uint32, uint64, int32 and +// int64, and sdk.Int scalars. +func NewIntValueRenderer() ValueRenderer { + return intValueRenderer{} +} + type intValueRenderer struct{} var _ ValueRenderer = intValueRenderer{} diff --git a/tx/textual/valuerenderer/protoreflect_list_test.go b/tx/textual/valuerenderer/protoreflect_list_test.go new file mode 100644 index 000000000000..ce11a01145e0 --- /dev/null +++ b/tx/textual/valuerenderer/protoreflect_list_test.go @@ -0,0 +1,64 @@ +package valuerenderer_test + +import ( + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" +) + +var _ protoreflect.List = (*genericList[proto.Message])(nil) + +// NewGenericList creates a empty list that satisfies the protoreflect.List +// interface. +func NewGenericList[T proto.Message](list []T) protoreflect.List { + return &genericList[T]{&list} +} + +// genericList is an implementation of protoreflect.List for a generic +type genericList[T proto.Message] struct { + list *[]T +} + +func (x *genericList[T]) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *genericList[T]) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *genericList[T]) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(T) + (*x.list)[i] = concreteValue +} + +func (x *genericList[T]) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(T) + *x.list = append(*x.list, concreteValue) +} + +func (x *genericList[T]) AppendMutable() protoreflect.Value { + v := *new(T) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *genericList[T]) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = *new(T) + } + *x.list = (*x.list)[:n] +} + +func (x *genericList[T]) NewElement() protoreflect.Value { + v := *new(T) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *genericList[T]) IsValid() bool { + return x.list != nil +} diff --git a/tx/textual/valuerenderer/valuerenderer.go b/tx/textual/valuerenderer/valuerenderer.go index da4fe0dbf575..a21f96d15145 100644 --- a/tx/textual/valuerenderer/valuerenderer.go +++ b/tx/textual/valuerenderer/valuerenderer.go @@ -1,25 +1,45 @@ package valuerenderer import ( + "context" "fmt" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/known/timestamppb" + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" cosmos_proto "github.com/cosmos/cosmos-proto" ) +// CoinMetadataQueryFn defines a function that queries state for the coin denom +// metadata. It is meant to be passed as an argument into `NewTextual`. +type CoinMetadataQueryFn func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) + // Textual holds the configuration for dispatching // to specific value renderers for SIGN_MODE_TEXTUAL. type Textual struct { - scalars map[string]ValueRenderer + // coinMetadataQuerier defines a function to query the coin metadata from + // state. It should use bank module's `DenomsMetadata` gRPC query to fetch + // each denom's associated metadata, either using the bank keeper (for + // server-side code) or a gRPC query client (for client-side code). + coinMetadataQuerier CoinMetadataQueryFn + // scalars defines a registry for Cosmos scalars. + scalars map[string]ValueRenderer + // messages defines a registry for custom message renderers, as defined in + // point #9 in the spec. Note that we also use this same registry for the + // following messages, as they can be thought of custom message rendering: + // - SDK coin and coins + // - Protobuf timestamp + // - Protobuf duration messages map[protoreflect.FullName]ValueRenderer } // NewTextual returns a new Textual which provides // value renderers. -func NewTextual() Textual { - t := Textual{} +func NewTextual(q CoinMetadataQueryFn) Textual { + t := Textual{coinMetadataQuerier: q} t.init() return t } @@ -43,7 +63,7 @@ func (r Textual) GetValueRenderer(fd protoreflect.FieldDescriptor) (ValueRendere return vr, nil } case fd.Kind() == protoreflect.BytesKind: - return bytesValueRenderer{}, nil + return NewBytesValueRenderer(), nil // Integers case fd.Kind() == protoreflect.Uint32Kind || @@ -51,7 +71,7 @@ func (r Textual) GetValueRenderer(fd protoreflect.FieldDescriptor) (ValueRendere fd.Kind() == protoreflect.Int32Kind || fd.Kind() == protoreflect.Int64Kind: { - return intValueRenderer{}, nil + return NewIntValueRenderer(), nil } case fd.Kind() == protoreflect.MessageKind: @@ -73,12 +93,13 @@ func (r Textual) GetValueRenderer(fd protoreflect.FieldDescriptor) (ValueRendere func (r *Textual) init() { if r.scalars == nil { r.scalars = map[string]ValueRenderer{} - r.scalars["cosmos.Int"] = intValueRenderer{} - r.scalars["cosmos.Dec"] = decValueRenderer{} + r.scalars["cosmos.Int"] = NewIntValueRenderer() + r.scalars["cosmos.Dec"] = NewDecValueRenderer() } if r.messages == nil { r.messages = map[protoreflect.FullName]ValueRenderer{} - r.messages["google.protobuf.Timestamp"] = NewTimestampValueRenderer() + r.messages[(&basev1beta1.Coin{}).ProtoReflect().Descriptor().FullName()] = NewCoinsValueRenderer(r.coinMetadataQuerier) + r.messages[(×tamppb.Timestamp{}).ProtoReflect().Descriptor().FullName()] = NewTimestampValueRenderer() } } diff --git a/tx/textual/valuerenderer/valuerenderer_test.go b/tx/textual/valuerenderer/valuerenderer_test.go index c8d9eeab45e3..5db655592893 100644 --- a/tx/textual/valuerenderer/valuerenderer_test.go +++ b/tx/textual/valuerenderer/valuerenderer_test.go @@ -11,7 +11,6 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/protobuf/reflect/protoreflect" - tspb "google.golang.org/protobuf/types/known/timestamppb" "cosmossdk.io/math" "cosmossdk.io/tx/textual/internal/testpb" @@ -26,11 +25,13 @@ func TestFormatInteger(t *testing.T) { err = json.Unmarshal(raw, &testcases) require.NoError(t, err) + textual := valuerenderer.NewTextual(nil) + for _, tc := range testcases { // Parse test case strings as protobuf uint64 i, err := strconv.ParseUint(tc[0], 10, 64) if err == nil { - r, err := valueRendererOf(i) + r, err := textual.GetValueRenderer(fieldDescriptorFromName("UINT64")) require.NoError(t, err) b := new(strings.Builder) err = r.Format(context.Background(), protoreflect.ValueOf(i), b) @@ -42,7 +43,7 @@ func TestFormatInteger(t *testing.T) { // Parse test case strings as protobuf uint32 i, err = strconv.ParseUint(tc[0], 10, 32) if err == nil { - r, err := valueRendererOf(i) + r, err := textual.GetValueRenderer(fieldDescriptorFromName("UINT32")) require.NoError(t, err) b := new(strings.Builder) err = r.Format(context.Background(), protoreflect.ValueOf(i), b) @@ -52,9 +53,9 @@ func TestFormatInteger(t *testing.T) { } // Parse test case strings as sdk.Ints - sdkInt, ok := math.NewIntFromString(tc[0]) + _, ok := math.NewIntFromString(tc[0]) if ok { - r, err := valueRendererOf(sdkInt) + r, err := textual.GetValueRenderer(fieldDescriptorFromName("SDKINT")) require.NoError(t, err) b := new(strings.Builder) err = r.Format(context.Background(), protoreflect.ValueOf(tc[0]), b) @@ -73,12 +74,12 @@ func TestFormatDecimal(t *testing.T) { err = json.Unmarshal(raw, &testcases) require.NoError(t, err) + textual := valuerenderer.NewTextual(nil) + for _, tc := range testcases { tc := tc t.Run(tc[0], func(t *testing.T) { - d, err := math.LegacyNewDecFromStr(tc[0]) - require.NoError(t, err) - r, err := valueRendererOf(d) + r, err := textual.GetValueRenderer(fieldDescriptorFromName("SDKDEC")) require.NoError(t, err) b := new(strings.Builder) err = r.Format(context.Background(), protoreflect.ValueOf(tc[0]), b) @@ -89,74 +90,47 @@ func TestFormatDecimal(t *testing.T) { } } -func TestGetADR050ValueRenderer(t *testing.T) { +func TestDispatcher(t *testing.T) { testcases := []struct { - name string - v interface{} - expErr bool + name string + expErr bool + expValueRenderer valuerenderer.ValueRenderer }{ - {"uint32", uint32(1), false}, - {"uint64", uint64(1), false}, - {"sdk.Int", math.NewInt(1), false}, - {"sdk.Dec", math.LegacyNewDec(1), false}, - {"[]byte", []byte{1}, false}, - {"float32", float32(1), true}, - {"float64", float64(1), true}, + {"UINT32", false, valuerenderer.NewIntValueRenderer()}, + {"UINT64", false, valuerenderer.NewIntValueRenderer()}, + {"SDKINT", false, valuerenderer.NewIntValueRenderer()}, + {"SDKDEC", false, valuerenderer.NewDecValueRenderer()}, + {"BYTES", false, valuerenderer.NewBytesValueRenderer()}, + {"TIMESTAMP", false, valuerenderer.NewTimestampValueRenderer()}, + {"COIN", false, valuerenderer.NewCoinsValueRenderer(nil)}, + {"COINS", false, valuerenderer.NewCoinsValueRenderer(nil)}, + {"FLOAT", true, nil}, } for _, tc := range testcases { tc := tc t.Run(tc.name, func(t *testing.T) { - _, err := valueRendererOf(tc.v) + textual := valuerenderer.NewTextual(nil) + rend, err := textual.GetValueRenderer(fieldDescriptorFromName(tc.name)) + if tc.expErr { require.Error(t, err) } else { require.NoError(t, err) + require.IsType(t, tc.expValueRenderer, rend) } }) } } -func TestTimestampDispatch(t *testing.T) { - a := (&testpb.A{}).ProtoReflect().Descriptor().Fields() - textual := valuerenderer.NewTextual() - rend, err := textual.GetValueRenderer(a.ByName(protoreflect.Name("TIMESTAMP"))) - require.NoError(t, err) - require.IsType(t, valuerenderer.NewTimestampValueRenderer(), rend) -} - -// valueRendererOf is like GetADR050ValueRenderer, but taking a Go type +// fieldDescriptorFromName is like GetADR050ValueRenderer, but taking a Go type // as input instead of a protoreflect.FieldDescriptor. -func valueRendererOf(v interface{}) (valuerenderer.ValueRenderer, error) { - a, b := (&testpb.A{}).ProtoReflect().Descriptor().Fields(), (&testpb.B{}).ProtoReflect().Descriptor().Fields() - - textual := valuerenderer.NewTextual() - switch v := v.(type) { - // Valid types for SIGN_MODE_TEXTUAL - case uint32: - return textual.GetValueRenderer(a.ByName(protoreflect.Name("UINT32"))) - case uint64: - return textual.GetValueRenderer(a.ByName(protoreflect.Name("UINT64"))) - case int32: - return textual.GetValueRenderer(a.ByName(protoreflect.Name("INT32"))) - case int64: - return textual.GetValueRenderer(a.ByName(protoreflect.Name("INT64"))) - case []byte: - return textual.GetValueRenderer(a.ByName(protoreflect.Name("BYTES"))) - case math.Int: - return textual.GetValueRenderer(a.ByName(protoreflect.Name("SDKINT"))) - case math.LegacyDec: - return textual.GetValueRenderer(a.ByName(protoreflect.Name("SDKDEC"))) - case tspb.Timestamp: - return textual.GetValueRenderer(a.ByName(protoreflect.Name("TIMESTAMP"))) - - // Invalid types for SIGN_MODE_TEXTUAL - case float32: - return textual.GetValueRenderer(b.ByName(protoreflect.Name("FLOAT"))) - case float64: - return textual.GetValueRenderer(b.ByName(protoreflect.Name("FLOAT"))) - - default: - return nil, fmt.Errorf("value %s of type %T not recognized", v, v) +func fieldDescriptorFromName(name string) protoreflect.FieldDescriptor { + a := (&testpb.A{}).ProtoReflect().Descriptor().Fields() + fd := a.ByName(protoreflect.Name(name)) + if fd == nil { + panic(fmt.Errorf("no field descriptor for %s", name)) } + + return fd }