forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR cosmos#2375: Add an example for the size of a transaction
* Add an example for the size of a transaction This shows that the size of a send tx from 1 input to 1 output is 173 bytes This is good information to have, though we need to find the correct place to put it. * fix lint
- Loading branch information
1 parent
a65c6eb
commit 8774adc
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/cmd/gaia/app" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth" | ||
"github.com/cosmos/cosmos-sdk/x/bank" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
) | ||
|
||
// This will fail half the time with the second output being 173 | ||
// This is due to secp256k1 signatures not being constant size. | ||
// This will be resolved when updating to tendermint v0.24.0 | ||
// nolint: vet | ||
func ExampleTxSendSize() { | ||
cdc := app.MakeCodec() | ||
priv1 := secp256k1.GenPrivKeySecp256k1([]byte{0}) | ||
addr1 := sdk.AccAddress(priv1.PubKey().Address()) | ||
priv2 := secp256k1.GenPrivKeySecp256k1([]byte{1}) | ||
addr2 := sdk.AccAddress(priv2.PubKey().Address()) | ||
coins := []sdk.Coin{sdk.NewCoin("denom", sdk.NewInt(10))} | ||
msg1 := bank.MsgSend{ | ||
Inputs: []bank.Input{bank.NewInput(addr1, coins)}, | ||
Outputs: []bank.Output{bank.NewOutput(addr2, coins)}, | ||
} | ||
sig, _ := priv1.Sign(msg1.GetSignBytes()) | ||
sigs := []auth.StdSignature{auth.StdSignature{nil, sig, 0, 0}} | ||
tx := auth.NewStdTx([]sdk.Msg{msg1}, auth.NewStdFee(0, coins...), sigs, "") | ||
fmt.Println(len(cdc.MustMarshalBinaryBare([]sdk.Msg{msg1}))) | ||
fmt.Println(len(cdc.MustMarshalBinaryBare(tx))) | ||
// output: 80 | ||
// 173 | ||
} |