suidouble 0.0.51 → 1.0.4-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,108 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap');
4
+ const { test } = t;
5
+ const path = require('path');
6
+
7
+ const { SuiMaster, SuiLocalTestValidator } = require('..');
8
+
9
+ let suiLocalTestValidator = null;
10
+ let suiMaster = null;
11
+ let contract = null;
12
+
13
+ let store = null;
14
+
15
+ test('spawn local test node', async t => {
16
+ suiLocalTestValidator = await SuiLocalTestValidator.launch({ testFallbackEnabled: true });
17
+ t.ok(suiLocalTestValidator.active);
18
+
19
+ // SuiLocalTestValidator runs as signle instance. So you can't start it twice with static method
20
+ const suiLocalTestValidatorCopy = await SuiLocalTestValidator.launch();
21
+ t.equal(suiLocalTestValidator, suiLocalTestValidatorCopy);
22
+ });
23
+
24
+ test('init suiMaster and connect it to local test validator', async t => {
25
+ suiMaster = new SuiMaster({client: suiLocalTestValidator, as: 'somebody', debug: true});
26
+ await suiMaster.initialize();
27
+
28
+ t.ok(suiMaster.address); // there should be some address
29
+ t.ok(`${suiMaster.address}`.indexOf('0x') === 0); // adress is string starting with '0x'
30
+ });
31
+ test('request sui from faucet', async t => {
32
+ const balanceBefore = await suiMaster.getBalance();
33
+ await suiMaster.requestSuiFromFaucet();
34
+
35
+ const balanceAfter = await suiMaster.getBalance();
36
+
37
+ t.ok(balanceAfter > balanceBefore);
38
+ });
39
+
40
+ test('attach a local package', async t => {
41
+ contract = suiMaster.addPackage({
42
+ path: path.join(__dirname, './test_move_contracts/different_types/'),
43
+ });
44
+ await contract.build();
45
+ await contract.publish();
46
+
47
+ store = suiMaster.objectStorage.findMostRecentByTypeName('Store'); // should be in local objectStorage after publish
48
+ await store.fetchFields();
49
+ t.ok(store.fields.numbers == 0); // values on init
50
+ });
51
+
52
+ test('try to update store with different types', async t => {
53
+ await contract.moveCall('different_types', 'put_u8', [ store.id, contract.arg('u8', 77) ]);
54
+ await contract.moveCall('different_types', 'put_u16', [ store.id, contract.arg('u16', 77) ]);
55
+ await contract.moveCall('different_types', 'put_u32', [ store.id, contract.arg('u32', 77) ]);
56
+ await contract.moveCall('different_types', 'put_u64', [ store.id, contract.arg('u64', 77) ]);
57
+ await contract.moveCall('different_types', 'put_u128', [ store.id, contract.arg('u128', 77) ]);
58
+ await contract.moveCall('different_types', 'put_u256', [ store.id, contract.arg('u256', 77) ]);
59
+
60
+ await store.fetchFields();
61
+ t.ok(store.fields.numbers == 6 * 77); // incremented 6 times by 77
62
+
63
+ await contract.moveCall('different_types', 'put_vector_u16', [ store.id, contract.arg('vector<u16>', [77,77,77,77]) ]);
64
+
65
+ await store.fetchFields();
66
+ t.ok(store.fields.numbers == 10 * 77); // plus 4 more times by 77
67
+
68
+ await contract.moveCall('different_types', 'put_bool', [ store.id, contract.arg('bool', true) ]);
69
+ await contract.moveCall('different_types', 'put_address', [ store.id, contract.arg('address', store.id) ]);
70
+
71
+ await store.fetchFields();
72
+ t.ok(store.fields.v_bool == true);
73
+ t.ok(store.fields.v_address == store.id);
74
+
75
+ await contract.moveCall('different_types', 'put_string', [ store.id, contract.arg('string', 'test') ]);
76
+
77
+ await store.fetchFields();
78
+ t.ok(store.fields.v_string == 'test');
79
+ });
80
+
81
+ test('module has same methods for args', async t => {
82
+ const mod = contract.modules.different_types;
83
+ await mod.moveCall('put_string', [ store.id, mod.arg('string', 'another test') ]);
84
+
85
+ await store.fetchFields();
86
+ t.ok(store.fields.v_string == 'another test');
87
+ });
88
+
89
+ test('passing typeArguments parameters', async t => {
90
+ const mod = contract.modules.different_types;
91
+
92
+ await mod.moveCall('put_type', [ store.id ], [ 'bool' ]);
93
+
94
+ await store.fetchFields();
95
+ t.ok(store.fields.v_string == 'bool');
96
+
97
+
98
+ await mod.moveCall('put_type', [ store.id ], [ store.type ]);
99
+ await store.fetchFields();
100
+
101
+ // it's '_____packageid____::different_types::Store'
102
+ t.ok(store.fields.v_string.indexOf('::different_types::Store') > 0);
103
+ });
104
+
105
+
106
+ test('stops local test node', async t => {
107
+ await SuiLocalTestValidator.stop();
108
+ });
@@ -13,7 +13,7 @@ test('initialization', async t => {
13
13
  });
14
14
 
15
15
  test('pseudo-random keypairs generation works ok', async t => {
16
- const suiMaster = new SuiMaster({provider: 'test', as: 'somebody'});
16
+ const suiMaster = new SuiMaster({client: 'test', as: 'somebody'});
17
17
  await suiMaster.initialize();
18
18
 
19
19
  // pseudo-random generation of 'somebody' is a keypair for a wallet '0x15b9493fb639a3118fed766ca80c1da62fa20493c293f319cc7d136506d2db69'
@@ -24,7 +24,7 @@ test('pseudo-random keypairs generation works ok', async t => {
24
24
  t.ok(suiMaster.address); // there should be some address
25
25
  t.ok(`${suiMaster.address}`.indexOf('0x') === 0); // adress is string starting with '0x'
26
26
 
27
- const suiMasterAsAdmin = new SuiMaster({provider: 'test', as: 'admin'});
27
+ const suiMasterAsAdmin = new SuiMaster({client: 'test', as: 'admin'});
28
28
  await suiMasterAsAdmin.initialize();
29
29
 
30
30
  t.ok(suiMasterAsAdmin.address); // there should be some address
@@ -33,7 +33,7 @@ test('pseudo-random keypairs generation works ok', async t => {
33
33
  t.not(`${suiMaster.address}`, `${suiMasterAsAdmin.address}`, 'different pseudo randoms should be different');
34
34
 
35
35
  /// but if you pass the same string as 'as' - it will generate the same keypair:
36
- const suiMasterAsAdminAnother = new SuiMaster({provider: 'test', as: 'admin'});
36
+ const suiMasterAsAdminAnother = new SuiMaster({client: 'test', as: 'admin'});
37
37
  await suiMasterAsAdminAnother.initialize();
38
38
 
39
39
  t.equal(`${suiMasterAsAdminAnother.address}`, `${suiMasterAsAdmin.address}`, 'same string should generate same pseudo-random');
@@ -42,15 +42,15 @@ test('pseudo-random keypairs generation works ok', async t => {
42
42
  test('keypair generation with seed phrase works ok', async t => {
43
43
  // Ed25519
44
44
  const phrase = 'seek weekend run rival noodle dog alone mosquito decide hover aerobic fiction'; // 0x2bfe9c35ca9400c42e24e4b424cbd2dfb51bcb7c2487e1b4694ff53d8ca00262
45
- const suiMaster = new SuiMaster({provider: 'test', phrase: phrase});
45
+ const suiMaster = new SuiMaster({client: 'test', phrase: phrase});
46
46
  await suiMaster.initialize();
47
47
 
48
48
  t.equal(`${suiMaster.address}`, `0x2bfe9c35ca9400c42e24e4b424cbd2dfb51bcb7c2487e1b4694ff53d8ca00262`, 'Ed25519 generated ok');
49
49
 
50
- const suiMasterNextAccount = new SuiMaster({provider: 'test', phrase: phrase, accountIndex: 1}); // default = 0
50
+ const suiMasterNextAccount = new SuiMaster({client: 'test', phrase: phrase, accountIndex: 1}); // default = 0
51
51
  await suiMasterNextAccount.initialize();
52
52
 
53
- t.notEqual(`${suiMaster.address}`, `${suiMasterNextAccount.address}`);
53
+ t.not(`${suiMaster.address}`, `${suiMasterNextAccount.address}`);
54
54
 
55
55
  t.equal(`${suiMasterNextAccount.address}`, `0xa6fb5c51b751e07a3e3b3af1f40f3115004702aad5a96263ff0be9078195f43b`, 'Ed25519 next account generated ok');
56
56
  });
@@ -58,15 +58,15 @@ test('keypair generation with seed phrase works ok', async t => {
58
58
  test('keypair generation with seed phrase works ok with secp256r1', async t => {
59
59
  // Ed25519
60
60
  const phrase = 'seek weekend run rival noodle dog alone mosquito decide hover aerobic fiction'; //
61
- const suiMaster = new SuiMaster({provider: 'test', phrase: phrase, keypairAlgo: 'secp256r1'});
61
+ const suiMaster = new SuiMaster({client: 'test', phrase: phrase, keypairAlgo: 'secp256r1'});
62
62
  await suiMaster.initialize();
63
63
 
64
64
  t.equal(`${suiMaster.address}`, `0x444f18d480b4d776d7679fae88ebb4f274941a81c3d98db430f7bd13f82e287d`, 'secp256r1 generated ok');
65
65
 
66
- const suiMasterNextAccount = new SuiMaster({provider: 'test', phrase: phrase, accountIndex: 1, keypairAlgo: 'secp256r1'}); // default = 0
66
+ const suiMasterNextAccount = new SuiMaster({client: 'test', phrase: phrase, accountIndex: 1, keypairAlgo: 'secp256r1'}); // default = 0
67
67
  await suiMasterNextAccount.initialize();
68
68
 
69
- t.notEqual(`${suiMaster.address}`, `${suiMasterNextAccount.address}`);
69
+ t.not(`${suiMaster.address}`, `${suiMasterNextAccount.address}`);
70
70
 
71
71
  t.equal(`${suiMasterNextAccount.address}`, `0xae496597c64aa6b1aaa03792c0ba0a725b1212adcb0df85d22c447cd57c21c95`, 'secp256r1 next account generated ok');
72
72
  });
@@ -75,21 +75,21 @@ test('keypair generation with seed phrase works ok with secp256r1', async t => {
75
75
  test('keypair generation with seed phrase works ok with secp256k1', async t => {
76
76
  // Ed25519
77
77
  const phrase = 'seek weekend run rival noodle dog alone mosquito decide hover aerobic fiction'; //
78
- const suiMaster = new SuiMaster({provider: 'test', phrase: phrase, keypairAlgo: 'secp256k1'});
78
+ const suiMaster = new SuiMaster({client: 'test', phrase: phrase, keypairAlgo: 'secp256k1'});
79
79
  await suiMaster.initialize();
80
80
 
81
81
  t.equal(`${suiMaster.address}`, `0x86a5dd3def25cab060af90f438842524894c7901839a954b2e9547ecc0f35ef8`, 'secp256k1 generated ok');
82
82
 
83
- const suiMasterNextAccount = new SuiMaster({provider: 'test', phrase: phrase, accountIndex: 1, keypairAlgo: 'secp256k1'}); // default = 0
83
+ const suiMasterNextAccount = new SuiMaster({client: 'test', phrase: phrase, accountIndex: 1, keypairAlgo: 'secp256k1'}); // default = 0
84
84
  await suiMasterNextAccount.initialize();
85
85
 
86
- t.notEqual(`${suiMaster.address}`, `${suiMasterNextAccount.address}`);
86
+ t.not(`${suiMaster.address}`, `${suiMasterNextAccount.address}`);
87
87
 
88
88
  t.equal(`${suiMasterNextAccount.address}`, `0xc5390344b0344a3e657176eaf72ca00ecf3ed4ec791640b6fc65a11cb680c53f`, 'secp256k1 next account generated ok');
89
89
  });
90
90
 
91
91
  test('SuiMaster has MIST_PER_SUI property available as BigInt', async t => {
92
- const suiMaster = new SuiMaster({provider: 'test', as: 'somebody'});
92
+ const suiMaster = new SuiMaster({client: 'test', as: 'somebody'});
93
93
 
94
94
  t.ok(suiMaster.MIST_PER_SUI);
95
95
 
@@ -102,22 +102,22 @@ test('SuiMaster has MIST_PER_SUI property available as BigInt', async t => {
102
102
  });
103
103
 
104
104
  test('connecting to different chains', async t => {
105
- const suiMaster = new SuiMaster({provider: 'test', as: 'somebody'});
105
+ const suiMaster = new SuiMaster({client: 'test', as: 'somebody'});
106
106
  await suiMaster.initialize();
107
107
 
108
108
  t.equal(suiMaster.connectedChain, 'sui:testnet');
109
109
 
110
- const suiMaster2 = new SuiMaster({provider: 'dev', as: 'somebody'});
110
+ const suiMaster2 = new SuiMaster({client: 'dev', as: 'somebody'});
111
111
  await suiMaster2.initialize();
112
112
 
113
113
  t.equal(suiMaster2.connectedChain, 'sui:devnet');
114
114
 
115
- const suiMaster3 = new SuiMaster({provider: 'main', as: 'somebody'});
115
+ const suiMaster3 = new SuiMaster({client: 'main', as: 'somebody'});
116
116
  await suiMaster3.initialize();
117
117
 
118
118
  t.equal(suiMaster3.connectedChain, 'sui:mainnet');
119
119
 
120
- const suiMaster4 = new SuiMaster({provider: 'local', as: 'somebody'});
120
+ const suiMaster4 = new SuiMaster({client: 'local', as: 'somebody'});
121
121
  await suiMaster4.initialize();
122
122
 
123
123
  t.equal(suiMaster4.connectedChain, 'sui:localnet');
@@ -27,7 +27,7 @@ test('spawn local test node', async t => {
27
27
  });
28
28
 
29
29
  test('init suiMaster and connect it to local test validator', async t => {
30
- suiMaster = new SuiMaster({provider: suiLocalTestValidator, as: 'somebody', debug: true});
30
+ suiMaster = new SuiMaster({client: suiLocalTestValidator, as: 'somebody', debug: true});
31
31
  await suiMaster.initialize();
32
32
 
33
33
  t.ok(suiMaster.address); // there should be some address
@@ -97,7 +97,7 @@ test('attach a local package', async t => {
97
97
  });
98
98
 
99
99
  test('attach a package by address on the blockchain', async t => {
100
- suiMaster = new SuiMaster({provider: suiLocalTestValidator, as: 'somebody'});
100
+ suiMaster = new SuiMaster({client: suiLocalTestValidator, as: 'somebody'});
101
101
  await suiMaster.initialize();
102
102
 
103
103
  contract = await suiMaster.addPackage({
@@ -124,7 +124,7 @@ test('attach a package by address on the blockchain', async t => {
124
124
  });
125
125
 
126
126
  test('can find a package on the blockchain by expected module name (in owned)', async t => {
127
- suiMaster = new SuiMaster({provider: suiLocalTestValidator, as: 'somebody'});
127
+ suiMaster = new SuiMaster({client: suiLocalTestValidator, as: 'somebody'});
128
128
  await suiMaster.initialize();
129
129
 
130
130
  contract = await suiMaster.addPackage({
@@ -166,7 +166,7 @@ test('subscribe to module events', async t => {
166
166
  gotEventChatResponseCreated = event.detail; // .detail is reference to event itself. To support CustomEvent pattern
167
167
  });
168
168
 
169
- await contract.moveCall('suidouble_chat', 'post', [chatShopObjectId, 'the message', 'metadata']);
169
+ await contract.moveCall('suidouble_chat', 'post', [chatShopObjectId, contract.arg('string', 'the message'), contract.arg('string', 'metadata')]);
170
170
  await new Promise((res)=>setTimeout(res, 300)); // got events without timeout, but just to be sure.
171
171
 
172
172
  t.ok(gotEventChatTopMessageCreated);
@@ -181,7 +181,7 @@ test('subscribe to module events', async t => {
181
181
  });
182
182
 
183
183
  test('execute contract methods', async t => {
184
- const moveCallResult = await contract.moveCall('suidouble_chat', 'post', [chatShopObjectId, 'the message', 'metadata']);
184
+ const moveCallResult = await contract.moveCall('suidouble_chat', 'post', [chatShopObjectId, contract.arg('string', 'the message'), contract.arg('string', 'metadata')]);
185
185
 
186
186
  // there're at least some object created
187
187
  t.ok(moveCallResult.created.length > 0);
@@ -223,7 +223,7 @@ test('execute contract methods', async t => {
223
223
  t.ok(dynamicFields.data.length === 1);
224
224
 
225
225
  const responseTextAsBytes = [].slice.call(new TextEncoder().encode('ขอบคุณครับ, 🇺🇦')); // regular array with utf data
226
- const moveCallResult2 = await contract.moveCall('suidouble_chat', 'reply', [chatTopMessage.id, responseTextAsBytes, 'metadata']);
226
+ const moveCallResult2 = await contract.moveCall('suidouble_chat', 'reply', [chatTopMessage.id, contract.arg('string', 'ขอบคุณครับ, 🇺🇦'), contract.arg('string', 'metadata')]);
227
227
 
228
228
  // there're at least some object created
229
229
  t.ok(moveCallResult2.created.length > 0);
@@ -248,7 +248,7 @@ test('testing paginatedResponse', async t => {
248
248
  t.ok(chatTopMessage);
249
249
 
250
250
  // fill method create a lot of responses ( check out contract's code )
251
- const moveCallResult = await contract.moveCall('suidouble_chat', 'fill', [chatTopMessage.id, 'the message response', 'metadata']);
251
+ const moveCallResult = await contract.moveCall('suidouble_chat', 'fill', [chatTopMessage.id, contract.arg('string', 'the message response'), contract.arg('string', 'metadata')]);
252
252
  t.ok(moveCallResult.created.length >= 60); // it's 60 in move code, but let's keep chat flexible
253
253
 
254
254
  const eventsResponse = await contract.fetchEvents('suidouble_chat');
@@ -282,6 +282,8 @@ test('testing paginatedResponse', async t => {
282
282
 
283
283
  test('find owned module objects with query', async t => {
284
284
  const module = await contract.getModule('suidouble_chat');
285
+ await module.getNormalizedMoveFunction('fill');
286
+
285
287
  const paginatedResponse = await module.getOwnedObjects();
286
288
 
287
289
  let foundCount = 0;
@@ -319,10 +321,10 @@ test('testing move call with coins', async t => {
319
321
 
320
322
  const longMessageYouCanNotPostForFree = ('message ').padEnd(500, 'test');
321
323
  // can't post it for free (as per contract design)
322
- t.rejects(contract.moveCall('suidouble_chat', 'post', [chatShopObjectId, longMessageYouCanNotPostForFree, 'metadata']));
324
+ t.rejects(contract.moveCall('suidouble_chat', 'post', [chatShopObjectId, contract.arg('string', longMessageYouCanNotPostForFree), contract.arg('string', 'metadata')]));
323
325
 
324
326
  // but can post with with post_pay function sending some sui to it
325
- const moveCallResult = await contract.moveCall('suidouble_chat', 'post_pay', [chatShopObjectId, {type: 'SUI', amount: 400000000000n}, longMessageYouCanNotPostForFree, 'metadata']);
327
+ const moveCallResult = await contract.moveCall('suidouble_chat', 'post_pay', [chatShopObjectId, {type: 'SUI', amount: 400000000000n}, contract.arg('string', longMessageYouCanNotPostForFree), contract.arg('string', 'metadata')]);
326
328
 
327
329
  // there're at least some object created
328
330
  t.ok(moveCallResult.created.length > 0);
@@ -29,7 +29,7 @@ test('checking takeShared', async t => {
29
29
  t.ok(chatShop.address); // there should be some address
30
30
  t.ok(`${chatShop.address}`.indexOf('0x') === 0); // adress is string starting with '0x'
31
31
 
32
- await testScenario.moveCall('suidouble_chat', 'post', [chatShop.address, 'posting a message', 'metadata']);
32
+ await testScenario.moveCall('suidouble_chat', 'post', [chatShop.address, testScenario.arg('string', 'posting a message'), testScenario.arg('string', 'metadata')]);
33
33
  const chatTopMessage = testScenario.takeShared('ChatTopMessage');
34
34
 
35
35
  t.ok(chatTopMessage.address); // there should be some address
@@ -44,7 +44,7 @@ test('checking takeOwned', async t => {
44
44
  const chatTopMessage = testScenario.takeShared('ChatTopMessage');
45
45
  t.ok(chatTopMessage.address); // there should be some address
46
46
 
47
- await testScenario.moveCall('suidouble_chat', 'reply', [chatTopMessage.address, 'posting a response', 'metadata']);
47
+ await testScenario.moveCall('suidouble_chat', 'reply', [chatTopMessage.address, testScenario.arg('string', 'posting a response'), testScenario.arg('string', 'metadata')]);
48
48
  const chatResponse = testScenario.takeFromSender('ChatResponse');
49
49
 
50
50
  t.ok(chatResponse.address); // there should be some address
@@ -1,8 +1,9 @@
1
1
  # @generated by Move, please check-in and do not edit manually.
2
2
 
3
3
  [move]
4
- version = 0
5
-
4
+ version = 2
5
+ manifest_digest = "782E5DC5571D50504E8D0062C1C45607FF5A73378BE161077BCEF58ADEC1A3F5"
6
+ deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
6
7
  dependencies = [
7
8
  { name = "Sui" },
8
9
  ]
@@ -18,3 +19,8 @@ source = { git = "https://github.com/MystenLabs/sui.git", rev = "testnet", subdi
18
19
  dependencies = [
19
20
  { name = "MoveStdlib" },
20
21
  ]
22
+
23
+ [move.toolchain-version]
24
+ compiler-version = "1.25.1"
25
+ edition = "2024.beta"
26
+ flavor = "sui"
@@ -1,10 +1,11 @@
1
1
  [package]
2
- name = "suidouble_color"
2
+ name = "different_types"
3
3
  version = "0.0.1"
4
+ edition = "2024.beta"
4
5
 
5
6
  [dependencies]
6
7
  Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "testnet" }
7
8
 
8
9
  [addresses]
9
- suidouble_color = "0x0"
10
+ different_types = "0x0"
10
11
  sui = "0000000000000000000000000000000000000000000000000000000000000002"
@@ -0,0 +1,73 @@
1
+ module different_types::different_types {
2
+ use std::string::{Self, utf8, String};
3
+ use std::type_name;
4
+
5
+ /// A shared object. `key` ability is required.
6
+ public struct Store has key {
7
+ id: UID,
8
+ numbers: u256,
9
+ v_bool: bool,
10
+ v_address: address,
11
+ v_string: String,
12
+ }
13
+
14
+
15
+ /// Init function is often ideal place for initializing
16
+ /// a shared object as it is called only once.
17
+ /// To share an object `transfer::share_object` is used.
18
+ fun init(ctx: &mut TxContext) {
19
+ let id = object::new(ctx);
20
+ // Share the object to make it accessible to everyone!
21
+ transfer::share_object(Store {
22
+ id: id,
23
+ numbers: 0,
24
+ v_bool: false,
25
+ v_address: @0xABBA,
26
+ v_string: utf8(b""),
27
+ })
28
+ }
29
+
30
+ public entry fun put_u8(store: &mut Store, value: u8, _ctx: &mut TxContext) {
31
+ store.numbers = store.numbers + (value as u256);
32
+ }
33
+ public entry fun put_u16(store: &mut Store, value: u16, _ctx: &mut TxContext) {
34
+ store.numbers = store.numbers + (value as u256);
35
+ }
36
+ public entry fun put_u32(store: &mut Store, value: u32, _ctx: &mut TxContext) {
37
+ store.numbers = store.numbers + (value as u256);
38
+ }
39
+ public entry fun put_u64(store: &mut Store, value: u64, _ctx: &mut TxContext) {
40
+ store.numbers = store.numbers + (value as u256);
41
+ }
42
+ public entry fun put_u128(store: &mut Store, value: u128, _ctx: &mut TxContext) {
43
+ store.numbers = store.numbers + (value as u256);
44
+ }
45
+ public entry fun put_u256(store: &mut Store, value: u256, _ctx: &mut TxContext) {
46
+ store.numbers = store.numbers + (value as u256);
47
+ }
48
+ public entry fun put_vector_u16(store: &mut Store, value: vector<u16>, _ctx: &mut TxContext) {
49
+ let vec_length = vector::length(&value);
50
+ let mut i = 0;
51
+ while (i < vec_length) {
52
+ store.numbers = store.numbers + (*vector::borrow(&value, i) as u256);
53
+
54
+ i = i + 1;
55
+ };
56
+ }
57
+ public entry fun put_address(store: &mut Store, value: address, _ctx: &mut TxContext) {
58
+ store.v_address = value;
59
+ }
60
+ public entry fun put_bool(store: &mut Store, value: bool, _ctx: &mut TxContext) {
61
+ store.v_bool = value;
62
+ }
63
+ public entry fun put_string(store: &mut Store, value: String, _ctx: &mut TxContext) {
64
+ store.v_string = value;
65
+ }
66
+
67
+ public entry fun put_type<T>(store: &mut Store, _ctx: &mut TxContext) {
68
+ let typen = type_name::get<T>();
69
+ let type_as_string = typen.into_string(); // returns ascii string
70
+
71
+ store.v_string = string::from_ascii(type_as_string);
72
+ }
73
+ }
@@ -22,6 +22,6 @@ dependencies = [
22
22
  ]
23
23
 
24
24
  [move.toolchain-version]
25
- compiler-version = "1.22.0"
25
+ compiler-version = "1.25.1"
26
26
  edition = "legacy"
27
27
  flavor = "sui"
@@ -1,150 +0,0 @@
1
-
2
- module suidouble_color::suidouble_color {
3
- use sui::tx_context::{Self, sender, TxContext};
4
- use std::string::{Self, utf8, String};
5
- use sui::transfer;
6
- use sui::object::{Self, UID, ID};
7
- use std::vector::{Self, append, insert};
8
-
9
- use sui::event::emit;
10
-
11
- // The creator bundle: these two packages often go together.
12
- use sui::package;
13
- use sui::display;
14
-
15
- /// Text size overflow.
16
- const EInvalidColor: u64 = 0;
17
-
18
- // ======== Events =========
19
-
20
- /// Event. When a new color minted
21
- struct ColorCreated has copy, drop { id: ID, r: u8, g: u8, b: u8 }
22
-
23
- /// The Hero - an outstanding collection of digital art.
24
- struct Color has key, store {
25
- id: UID,
26
- name: String,
27
- r: u8,
28
- g: u8,
29
- b: u8,
30
- img_url: String,
31
- }
32
-
33
- /// One-Time-Witness for the module.
34
- struct SUIDOUBLE_COLOR has drop {}
35
-
36
- /// In the module initializer we claim the `Publisher` object
37
- /// to then create a `Display`. The `Display` is initialized with
38
- /// a set of fields (but can be modified later) and published via
39
- /// the `update_version` call.
40
- ///
41
- /// Keys and values are set in the initializer but could also be
42
- /// set after publishing if a `Publisher` object was created.
43
- fun init(otw: SUIDOUBLE_COLOR, ctx: &mut TxContext) {
44
- let keys = vector[
45
- utf8(b"name"),
46
- utf8(b"link"),
47
- utf8(b"image_url"),
48
- utf8(b"description"),
49
- utf8(b"project_url"),
50
- utf8(b"creator"),
51
- ];
52
-
53
- let values = vector[
54
- utf8(b"{name}"),
55
- // For `link` we can build a URL using an `id` property
56
- utf8(b"https://suidouble-color.herokuapp.com/color/{id}"),
57
- utf8(b"{img_url}"),
58
- // Description is static for all `Color` objects.
59
- utf8(b"What a nice color. Isn't it?"),
60
- // Project URL is usually static
61
- utf8(b"https://suidouble-color.herokuapp.com/"),
62
- // Creator field can be any
63
- utf8(b"Jeka")
64
- ];
65
-
66
- // Claim the `Publisher` for the package!
67
- let publisher = package::claim(otw, ctx);
68
-
69
- // Get a new `Display` object for the `Color` type.
70
- let display = display::new_with_fields<Color>(
71
- &publisher, keys, values, ctx
72
- );
73
-
74
- // Commit first version of `Display` to apply changes.
75
- display::update_version(&mut display);
76
-
77
- transfer::public_transfer(publisher, sender(ctx));
78
- transfer::public_transfer(display, sender(ctx));
79
- }
80
-
81
- /// Anyone can mint their `Color`!
82
- public entry fun mint(name: String, r: u8, g: u8, b: u8, ctx: &mut TxContext) {
83
- assert!(r >= 0 && r <= 255, EInvalidColor);
84
- assert!(g >= 0 && g <= 255, EInvalidColor);
85
- assert!(b >= 0 && b <= 255, EInvalidColor);
86
-
87
- let id = object::new(ctx);
88
-
89
- emit(ColorCreated { id: object::uid_to_inner(&id), r, g, b, });
90
-
91
- // constructing the smallest (1x1) GIF with the color of RGB
92
- let gif_start = vector<u8>[71, 73, 70, 56, 57, 97, 1, 0, 1, 0, 128, 1, 0];
93
- let gif_end = vector<u8>[0, 0, 0, 33, 249, 4, 1, 10, 0, 1, 0, 44, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 2, 68, 1, 0, 59];
94
-
95
- insert(&mut gif_start, r, 13); // appending R
96
- insert(&mut gif_start, g, 14); // appending G
97
- insert(&mut gif_start, b, 15); // appending B
98
- append(&mut gif_start, gif_end);
99
-
100
- let img_url = encode(&gif_start);
101
-
102
- let base_prefix = b"data:image/gif;base64,";
103
- let as_string = utf8(base_prefix);
104
- string::append(&mut as_string, utf8(img_url));
105
-
106
- //
107
- let color = Color { id, name, img_url: as_string, r: r, g: g, b: b };
108
-
109
- transfer::transfer(color, tx_context::sender(ctx));
110
- }
111
-
112
- // thanks to: https://github.com/movefuns/movefuns/blob/dd1f4443c6bf0bc761b27e28fb6ba00f10636840/stdlib/sources/base64.move#L2
113
- const TABLE: vector<u8> = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
114
-
115
- public fun encode(str: &vector<u8>): vector<u8> {
116
- if (vector::is_empty(str)) {
117
- return vector::empty<u8>()
118
- };
119
- let size = vector::length(str);
120
- let eq: u8 = 61;
121
- let res = vector::empty<u8>();
122
-
123
- let m = 0 ;
124
- while (m < size ) {
125
- vector::push_back(&mut res, *vector::borrow(&TABLE, (((*vector::borrow(str, m) & 0xfc) >> 2) as u64)));
126
- if ( m + 3 >= size) {
127
- if ( size % 3 == 1) {
128
- vector::push_back(&mut res, *vector::borrow(&TABLE, (((*vector::borrow(str, m) & 0x03) << 4) as u64)));
129
- vector::push_back(&mut res, eq);
130
- vector::push_back(&mut res, eq);
131
- }else if (size % 3 == 2) {
132
- vector::push_back(&mut res, *vector::borrow(&TABLE, ((((*vector::borrow(str, m) & 0x03) << 4) + ((*vector::borrow(str, m + 1) & 0xf0) >> 4)) as u64)));
133
- vector::push_back(&mut res, *vector::borrow(&TABLE, (((*vector::borrow(str, m + 1) & 0x0f) << 2) as u64)));
134
- vector::push_back(&mut res, eq);
135
- }else {
136
- vector::push_back(&mut res, *vector::borrow(&TABLE, ((((*vector::borrow(str, m) & 0x03) << 4) + ((*vector::borrow(str, m + 1) & 0xf0) >> 4)) as u64)));
137
- vector::push_back(&mut res, *vector::borrow(&TABLE, ((((*vector::borrow(str, m + 1) & 0x0f) << 2) + ((*vector::borrow(str, m + 2) & 0xc0) >> 6)) as u64)));
138
- vector::push_back(&mut res, *vector::borrow(&TABLE, ((*vector::borrow(str, m + 2) & 0x3f) as u64)));
139
- };
140
- }else {
141
- vector::push_back(&mut res, *vector::borrow(&TABLE, ((((*vector::borrow(str, m) & 0x03) << 4) + ((*vector::borrow(str, m + 1) & 0xf0) >> 4)) as u64)));
142
- vector::push_back(&mut res, *vector::borrow(&TABLE, ((((*vector::borrow(str, m + 1) & 0x0f) << 2) + ((*vector::borrow(str, m + 2) & 0xc0) >> 6)) as u64)));
143
- vector::push_back(&mut res, *vector::borrow(&TABLE, ((*vector::borrow(str, m + 2) & 0x3f) as u64)));
144
- };
145
- m = m + 3;
146
- };
147
-
148
- return res
149
- }
150
- }