Skip to content

Commit bc0f876

Browse files
committed
Merge branch 'fix-review' into deploy
2 parents 98666a7 + 343afa9 commit bc0f876

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+309
-315
lines changed

clients/chainclient/chainclient.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"math"
77

8+
"github.com/iotaledger/bcs-go"
89
"github.com/iotaledger/wasp/clients"
910
"github.com/iotaledger/wasp/clients/apiclient"
1011
"github.com/iotaledger/wasp/clients/apiextensions"
@@ -128,13 +129,12 @@ func (c *Client) postSingleRequest(
128129
Function: uint32(iscmsg.Target.EntryPoint),
129130
Args: iscmsg.Params,
130131
}
131-
allowances := iscmove.NewAssets(0)
132+
var allowanceBCS []byte
132133
if params.Allowance != nil {
133-
for coinType, coinBalance := range params.Allowance.Coins.Iterate() {
134-
allowances.AddCoin(iotajsonrpc.CoinType(coinType.String()), iotajsonrpc.CoinValue(coinBalance.Uint64()))
135-
}
136-
for obj := range params.Allowance.Objects.Iterate() {
137-
allowances.AddObject(obj.ID, obj.Type)
134+
var err error
135+
allowanceBCS, err = bcs.Marshal(params.Allowance.AsISCMove())
136+
if err != nil {
137+
return nil, fmt.Errorf("failed to marshal allowance: %w", err)
138138
}
139139
}
140140
return c.L1Client.L2().CreateAndSendRequestWithAssets(
@@ -145,7 +145,7 @@ func (c *Client) postSingleRequest(
145145
AnchorAddress: c.ChainID.AsAddress().AsIotaAddress(),
146146
Assets: transferAssets,
147147
Message: msg,
148-
Allowance: allowances,
148+
AllowanceBCS: allowanceBCS,
149149
OnchainGasBudget: params.GetL2GasBudget(),
150150
GasPrice: params.GetGasPrice(),
151151
GasBudget: params.GetGasBudget(),

clients/iota-go/iotaclient/iotaclienttest/api_exented_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestGetDynamicFieldObject(t *testing.T) {
6767

6868
func TestGetOwnedObjects(t *testing.T) {
6969
client := l1starter.Instance().L1Client()
70-
signer := iotasigner.NewSignerByIndex(testcommon.TestSeed, iotasigner.KeySchemeFlagEd25519, 0)
70+
signer := iotasigner.NewSignerByIndex(testcommon.TestSeed, iotasigner.KeySchemeFlagDefault, 0)
7171
t.Run(
7272
"struct tag", func(t *testing.T) {
7373
structTag, err := iotago.StructTagFromString("0x2::coin::Coin<0x2::iota::IOTA>")

clients/iota-go/iotasigner/iotasignertest/random.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func RandomSigner() iotasigner.Signer {
1414
if err != nil {
1515
panic(err)
1616
}
17-
return iotasigner.NewSigner(b, iotasigner.KeySchemeFlagIotaEd25519)
17+
return iotasigner.NewSigner(b, iotasigner.KeySchemeFlagDefault)
1818
}
1919

2020
func RandomSignedTransaction(signers ...iotasigner.Signer) iotasigner.SignedTransaction {

clients/iota-go/iotasigner/key_schemes.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
type KeySchemeFlag byte
99

10-
var KeySchemeFlagDefault = KeySchemeFlagIotaEd25519
10+
var KeySchemeFlagDefault = KeySchemeFlagEd25519
1111

1212
const (
1313
KeySchemeFlagEd25519 KeySchemeFlag = iota
@@ -17,8 +17,7 @@ const (
1717
KeySchemeFlagBLS12381
1818
KeySchemeFlagZkLoginAuthenticator
1919

20-
KeySchemeFlagIotaEd25519 KeySchemeFlag = math.MaxUint8 - 1 // special case for iotago ed25519
21-
KeySchemeFlagError = math.MaxUint8
20+
KeySchemeFlagError = math.MaxUint8
2221
)
2322

2423
func (k KeySchemeFlag) Byte() byte {

clients/iota-go/iotasigner/signer.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Bip32CoinType int
1818
const (
1919
// testnet/alphanet uses COIN_TYPE = 1
2020
TestnetCoinType Bip32CoinType = 1
21-
// / IOTA coin type <https://github.com/satoshilabs/slips/blob/master/slip-0044.md>
21+
// IOTA coin type <https://github.com/satoshilabs/slips/blob/master/slip-0044.md>
2222
IotaCoinType Bip32CoinType = 4218
2323
)
2424

@@ -59,7 +59,6 @@ type Signer interface {
5959
SignTransactionBlock(txnBytes []byte, intent Intent) (*Signature, error)
6060
}
6161

62-
// FIXME support more than ed25519
6362
type InMemorySigner struct {
6463
ed25519Keypair *KeypairEd25519
6564

@@ -70,20 +69,14 @@ func NewSigner(seed []byte, flag KeySchemeFlag) *InMemorySigner {
7069
prikey := ed25519.NewKeyFromSeed(seed)
7170
pubkey := prikey.Public().(ed25519.PublicKey)
7271

73-
// IOTA_DIFF iotago ignore flag when signature scheme is ed25519
74-
var buf []byte
75-
switch flag {
76-
case KeySchemeFlagEd25519:
77-
buf = []byte{KeySchemeFlagEd25519.Byte()}
78-
case KeySchemeFlagSecp256k1:
79-
buf = []byte{KeySchemeFlagEd25519.Byte()}
80-
case KeySchemeFlagIotaEd25519:
81-
buf = []byte{}
82-
default:
72+
// Right now only supports ED25519. Stardust *Addresses* used to include the scheme flag, Rebased does not.
73+
// https://docs.iota.org/developer/cryptography/transaction-auth/keys-addresses#address-format
74+
75+
if flag != KeySchemeFlagEd25519 {
8376
panic("unrecognizable key scheme flag")
8477
}
85-
buf = append(buf, pubkey...)
86-
addrBytes := blake2b.Sum256(buf)
78+
79+
addrBytes := blake2b.Sum256(pubkey)
8780
addr := "0x" + hex.EncodeToString(addrBytes[:])
8881

8982
return &InMemorySigner{
@@ -141,7 +134,6 @@ func (s *InMemorySigner) PublicKey() []byte {
141134
}
142135

143136
func (s *InMemorySigner) Sign(msg []byte) (signature *Signature, err error) {
144-
// FIXME support more than ed25519
145137
sig := ed25519.Sign(s.ed25519Keypair.PriKey, msg)
146138

147139
return &Signature{
@@ -153,7 +145,6 @@ func (s *InMemorySigner) Address() *iotago.Address {
153145
return s.address
154146
}
155147

156-
// FIXME support more than ed25519
157148
func (s *InMemorySigner) SignTransactionBlock(txnBytes []byte, intent Intent) (*Signature, error) {
158149
data := MessageWithIntent(intent, txnBytes)
159150
hash := blake2b.Sum256(data)

clients/iota-go/iotasigner/signer_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ import (
1414
)
1515

1616
func TestNewSigner(t *testing.T) {
17-
testIotaAddress := iotago.MustAddressFromHex("0x786dff8a4ee13d45b502c8f22f398e3517e6ec78aa4ae564c348acb07fad7f50")
18-
signer, err := iotasigner.NewSignerWithMnemonic(testcommon.TestMnemonic, iotasigner.KeySchemeFlagIotaEd25519)
19-
require.NoError(t, err)
20-
require.Equal(t, testIotaAddress, signer.Address())
21-
signer, err = iotasigner.NewSignerWithMnemonic(testcommon.TestMnemonic, iotasigner.KeySchemeFlagEd25519)
17+
signer, err := iotasigner.NewSignerWithMnemonic(testcommon.TestMnemonic, iotasigner.KeySchemeFlagDefault)
2218
require.NoError(t, err)
2319
require.Equal(t, iotago.MustAddressFromHex(testcommon.TestAddress), signer.Address())
2420
}

clients/iota-go/iotatest/faucet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func MakeSignerWithFunds(index int, faucetURL string) iotasigner.Signer {
1313
}
1414

1515
func MakeSignerWithFundsFromSeed(seed []byte, index int, faucetURL string) iotasigner.Signer {
16-
keySchemeFlag := iotasigner.KeySchemeFlagIotaEd25519
16+
keySchemeFlag := iotasigner.KeySchemeFlagDefault
1717

1818
// there are only 256 different signers can be generated
1919
signer := iotasigner.NewSignerByIndex(seed, keySchemeFlag, index)

clients/iota-go/test_common/consts.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,40 @@ package testcommon
22

33
const (
44
TestMnemonic = "ordinary cry margin host traffic bulb start zone mimic wage fossil eight diagram clay say remove add atom"
5-
TestAddress = "0xe54d993cf56be93ba0764c7ee2c817085b70f0e6d3ad1a71c3335ee3529b4a48"
5+
TestAddress = "0x786dff8a4ee13d45b502c8f22f398e3517e6ec78aa4ae564c348acb07fad7f50"
66
)
77

8-
var TestSeed = []byte{50, 230, 119, 9, 86, 155, 106, 30, 245, 81, 234, 122, 116, 90, 172, 148, 59, 33, 88, 252, 134, 42, 231, 198, 208, 141, 209, 116, 78, 21, 216, 24}
8+
var TestSeed = []byte{
9+
50,
10+
230,
11+
119,
12+
9,
13+
86,
14+
155,
15+
106,
16+
30,
17+
245,
18+
81,
19+
234,
20+
122,
21+
116,
22+
90,
23+
172,
24+
148,
25+
59,
26+
33,
27+
88,
28+
252,
29+
134,
30+
42,
31+
231,
32+
198,
33+
208,
34+
141,
35+
209,
36+
116,
37+
78,
38+
21,
39+
216,
40+
24,
41+
}

clients/iscmove/isc.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ func (o ObjectCollection) Iterate() iter.Seq2[iotago.ObjectID, iotago.ObjectType
222222
}
223223

224224
type Request struct {
225-
ID iotago.ObjectID
226-
Sender *cryptolib.Address
227-
// XXX balances are empty if we don't fetch the dynamic fields
228-
AssetsBag AssetsBagWithBalances // Need to decide if we want to use this Referent wrapper as well. Could probably be of *AssetsBag with `bcs:"optional`
225+
ID iotago.ObjectID
226+
Sender *cryptolib.Address
227+
AssetsBag AssetsBagWithBalances
229228
Message Message
230-
Allowance Assets
231-
GasBudget uint64
229+
// AllowanceBCS is either empty or a BCS-encoded iscmove.Allowance
230+
AllowanceBCS []byte
231+
GasBudget uint64
232232
}
233233

234234
type RequestEvent struct {

clients/iscmove/isc_test.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/iotaledger/wasp/clients/iota-go/iotaclient"
1010
"github.com/iotaledger/wasp/clients/iota-go/iotago"
1111
"github.com/iotaledger/wasp/clients/iota-go/iotago/iotatest"
12-
"github.com/iotaledger/wasp/clients/iota-go/iotajsonrpc"
1312
testcommon "github.com/iotaledger/wasp/clients/iota-go/test_common"
1413
"github.com/iotaledger/wasp/clients/iscmove"
1514
"github.com/iotaledger/wasp/clients/iscmove/iscmoveclient"
@@ -59,11 +58,8 @@ func TestUnmarshalBCS(t *testing.T) {
5958
},
6059
},
6160
},
62-
Message: *iscmovetest.RandomMessage(),
63-
Allowance: iscmove.Assets{
64-
Coins: iscmove.CoinBalances{iotajsonrpc.IotaCoinType: 100},
65-
Objects: iscmove.ObjectCollection{iotago.ObjectID{}: iotago.MustTypeFromString("0x1::a::A")},
66-
},
61+
Message: *iscmovetest.RandomMessage(),
62+
Allowance: []byte{1, 2, 3},
6763
GasBudget: 100,
6864
}
6965
b, err := bcs.Marshal(&req)
@@ -74,26 +70,3 @@ func TestUnmarshalBCS(t *testing.T) {
7470
err = iotaclient.UnmarshalBCS(b, &targetReq)
7571
require.Nil(t, err)
7672
}
77-
78-
func TestUnmarshalInvalidRequestBCS(t *testing.T) {
79-
req := iscmoveclient.MoveRequest{
80-
ID: *iotatest.RandomAddress(),
81-
Sender: cryptolib.NewAddressFromIota(iotatest.RandomAddress()),
82-
AssetsBag: iscmove.Referent[iscmove.AssetsBagWithBalances]{
83-
ID: *iotatest.RandomAddress(),
84-
Value: &iscmove.AssetsBagWithBalances{
85-
AssetsBag: iscmovetest.RandomAssetsBag(),
86-
Assets: *iscmove.NewEmptyAssets(),
87-
},
88-
},
89-
Message: *iscmovetest.RandomMessage(),
90-
Allowance: iscmove.Assets{
91-
Coins: iscmove.CoinBalances{"WRONG_TYPE": 100},
92-
Objects: iscmove.ObjectCollection{iotago.ObjectID{}: iotago.MustTypeFromString("0x1::a::A")},
93-
},
94-
GasBudget: 100,
95-
}
96-
_, err := bcs.Marshal(&req)
97-
require.Error(t, err)
98-
require.ErrorContains(t, err, "encoding")
99-
}

0 commit comments

Comments
 (0)