Skip to content

Commit 210f89d

Browse files
author
Maxim
committed
Update Peggy types from chain
1 parent 85bf8ac commit 210f89d

19 files changed

+356
-6505
lines changed

chain/peggy/types/abi_json.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,4 @@ const (
5050
{ "internalType": "bytes32", "name": "", "type": "bytes32" }
5151
]
5252
}]`
53-
54-
// OutgoingLogicCallABIJSON checks the ETH ABI for compatability of the logic call message
55-
OutgoingLogicCallABIJSON = `[{
56-
"name": "checkpoint",
57-
"outputs": [],
58-
"stateMutability": "pure",
59-
"type": "function",
60-
"inputs": [
61-
{ "internalType": "bytes32", "name": "_peggyId", "type": "bytes32" },
62-
{ "internalType": "bytes32", "name": "_methodName", "type": "bytes32" },
63-
{ "internalType": "uint256[]", "name": "_transferAmounts", "type": "uint256[]" },
64-
{ "internalType": "address[]", "name": "_transferTokenContracts", "type": "address[]" },
65-
{ "internalType": "uint256[]", "name": "_feeAmounts", "type": "uint256[]" },
66-
{ "internalType": "address[]", "name": "_feeTokenContracts", "type": "address[]" },
67-
{ "internalType": "address", "name": "_logicContractAddress", "type": "address" },
68-
{ "internalType": "bytes", "name": "_payload", "type": "bytes" },
69-
{ "internalType": "uint256", "name": "_timeout", "type": "uint256" },
70-
{ "internalType": "bytes32", "name": "_invalidationId", "type": "bytes32" },
71-
{ "internalType": "uint256", "name": "_invalidationNonce", "type": "uint256" }
72-
]
73-
}]`
7453
)

chain/peggy/types/batch.go

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -67,69 +67,3 @@ func (b OutgoingTxBatch) GetCheckpoint(peggyIDstring string) ([]byte, error) {
6767
// then need to adjust how many bytes you truncate off the front to get the output of abi.encode()
6868
return crypto.Keccak256Hash(abiEncodedBatch[4:]).Bytes(), nil
6969
}
70-
71-
// GetCheckpoint gets the checkpoint signature from the given outgoing tx batch
72-
func (c OutgoingLogicCall) GetCheckpoint(peggyIDstring string) ([]byte, error) {
73-
74-
abi, err := abi.JSON(strings.NewReader(OutgoingLogicCallABIJSON))
75-
if err != nil {
76-
return nil, sdkerrors.Wrap(err, "bad ABI definition in code")
77-
}
78-
79-
// Create the methodName argument which salts the signature
80-
methodNameBytes := []uint8("logicCall")
81-
var logicCallMethodName [32]uint8
82-
copy(logicCallMethodName[:], methodNameBytes[:])
83-
84-
// the contract argument is not a arbitrary length array but a fixed length 32 byte
85-
// array, therefore we have to utf8 encode the string (the default in this case) and
86-
// then copy the variable length encoded data into a fixed length array. This function
87-
// will panic if peggyId is too long to fit in 32 bytes
88-
peggyID, err := strToFixByteArray(peggyIDstring)
89-
if err != nil {
90-
panic(err)
91-
}
92-
93-
// Run through the elements of the logic call and serialize them
94-
transferAmounts := make([]*big.Int, len(c.Transfers))
95-
transferTokenContracts := make([]gethcommon.Address, len(c.Transfers))
96-
feeAmounts := make([]*big.Int, len(c.Fees))
97-
feeTokenContracts := make([]gethcommon.Address, len(c.Fees))
98-
for i, tx := range c.Transfers {
99-
transferAmounts[i] = tx.Amount.BigInt()
100-
transferTokenContracts[i] = gethcommon.HexToAddress(tx.Contract)
101-
}
102-
for i, tx := range c.Fees {
103-
feeAmounts[i] = tx.Amount.BigInt()
104-
feeTokenContracts[i] = gethcommon.HexToAddress(tx.Contract)
105-
}
106-
payload := make([]byte, len(c.Payload))
107-
copy(payload, c.Payload)
108-
var invalidationId [32]byte
109-
copy(invalidationId[:], c.InvalidationId[:])
110-
111-
// the methodName needs to be the same as the 'name' above in the checkpointAbiJson
112-
// but other than that it's a constant that has no impact on the output. This is because
113-
// it gets encoded as a function name which we must then discard.
114-
abiEncodedCall, err := abi.Pack("checkpoint",
115-
peggyID,
116-
logicCallMethodName,
117-
transferAmounts,
118-
transferTokenContracts,
119-
feeAmounts,
120-
feeTokenContracts,
121-
gethcommon.HexToAddress(c.LogicContractAddress),
122-
payload,
123-
big.NewInt(int64(c.Timeout)),
124-
invalidationId,
125-
big.NewInt(int64(c.InvalidationNonce)),
126-
)
127-
128-
// this should never happen outside of test since any case that could crash on encoding
129-
// should be filtered above.
130-
if err != nil {
131-
return nil, sdkerrors.Wrap(err, "packing checkpoint")
132-
}
133-
134-
return crypto.Keccak256Hash(abiEncodedCall[4:]).Bytes(), nil
135-
}

0 commit comments

Comments
 (0)