-
Notifications
You must be signed in to change notification settings - Fork 6
/
tx.go
51 lines (43 loc) · 1.22 KB
/
tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package tx
import (
"fmt"
codectypes "github.com/irisnet/core-sdk-go/common/codec/types"
sdk "github.com/irisnet/core-sdk-go/types"
)
func Unwrap(anyUnpacker codectypes.AnyUnpacker, tx sdk.Tx) (*sdk.UnwrappedTx, error) {
txWrapper, ok := tx.(*wrapper)
if !ok {
return nil, fmt.Errorf("expected %T, got %T", &wrapper{}, tx)
}
txBody := sdk.UnwrappedTxBody{
Msgs: txWrapper.tx.GetMsgs(),
Memo: txWrapper.tx.Body.Memo,
TimeoutHeight: txWrapper.tx.Body.TimeoutHeight,
}
var signatures []sdk.UnwrappedSignature
for i, pubKey := range txWrapper.GetPubKeys(anyUnpacker) {
bech32PubKey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKey)
if err != nil {
return nil, err
}
signatures = append(signatures, sdk.UnwrappedSignature{
PubKey: sdk.UnwrappedPubKey{
Type: pubKey.Type(),
Value: bech32PubKey,
},
Sig: txWrapper.tx.Signatures[i],
Sequence: txWrapper.tx.AuthInfo.SignerInfos[i].Sequence,
})
}
authInfo := sdk.UnwrappedAuthInfo{
Signatures: signatures,
Fee: &sdk.StdFee{
Amount: txWrapper.tx.AuthInfo.Fee.Amount,
Gas: txWrapper.tx.AuthInfo.Fee.GasLimit,
},
}
return &sdk.UnwrappedTx{
Body: txBody,
AuthInfo: authInfo,
}, nil
}